<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package URI;

use strict;
use warnings;

our $VERSION = '5.09';

our ($ABS_REMOTE_LEADING_DOTS, $ABS_ALLOW_RELATIVE_SCHEME, $DEFAULT_QUERY_FORM_DELIMITER);

my %implements;  # mapping from scheme to implementor class

# Some "official" character classes

our $reserved   = q(;/?:@&amp;=+$,[]);
our $mark       = q(-_.!~*'());                                    #'; emacs
our $unreserved = "A-Za-z0-9\Q$mark\E";
our $uric       = quotemeta($reserved) . $unreserved . "%";

our $scheme_re  = '[a-zA-Z][a-zA-Z0-9.+\-]*';

use Carp ();
use URI::Escape ();

use overload ('""'     =&gt; sub { ${$_[0]} },
              '=='     =&gt; sub { _obj_eq(@_) },
              '!='     =&gt; sub { !_obj_eq(@_) },
              fallback =&gt; 1,
             );

# Check if two objects are the same object
sub _obj_eq {
    return overload::StrVal($_[0]) eq overload::StrVal($_[1]);
}

sub new
{
    my($class, $uri, $scheme) = @_;

    $uri = defined ($uri) ? "$uri" : "";   # stringify
    # Get rid of potential wrapping
    $uri =~ s/^&lt;(?:URL:)?(.*)&gt;$/$1/;  # 
    $uri =~ s/^"(.*)"$/$1/;
    $uri =~ s/^\s+//;
    $uri =~ s/\s+$//;

    my $impclass;
    if ($uri =~ m/^($scheme_re):/so) {
	$scheme = $1;
    }
    else {
	if (($impclass = ref($scheme))) {
	    $scheme = $scheme-&gt;scheme;
	}
	elsif ($scheme &amp;&amp; $scheme =~ m/^($scheme_re)(?::|$)/o) {
	    $scheme = $1;
        }
    }
    $impclass ||= implementor($scheme) ||
	do {
	    require URI::_foreign;
	    $impclass = 'URI::_foreign';
	};

    return $impclass-&gt;_init($uri, $scheme);
}


sub new_abs
{
    my($class, $uri, $base) = @_;
    $uri = $class-&gt;new($uri, $base);
    $uri-&gt;abs($base);
}


sub _init
{
    my $class = shift;
    my($str, $scheme) = @_;
    # find all funny characters and encode the bytes.
    $str = $class-&gt;_uric_escape($str);
    $str = "$scheme:$str" unless $str =~ /^$scheme_re:/o ||
                                 $class-&gt;_no_scheme_ok;
    my $self = bless \$str, $class;
    $self;
}


sub _uric_escape
{
    my($class, $str) = @_;
    $str =~ s*([^$uric\#])* URI::Escape::escape_char($1) *ego;
    utf8::downgrade($str);
    return $str;
}

my %require_attempted;

sub implementor
{
    my($scheme, $impclass) = @_;
    if (!$scheme || $scheme !~ /\A$scheme_re\z/o) {
	require URI::_generic;
	return "URI::_generic";
    }

    $scheme = lc($scheme);

    if ($impclass) {
	# Set the implementor class for a given scheme
        my $old = $implements{$scheme};
        $impclass-&gt;_init_implementor($scheme);
        $implements{$scheme} = $impclass;
        return $old;
    }

    my $ic = $implements{$scheme};
    return $ic if $ic;

    # scheme not yet known, look for internal or
    # preloaded (with 'use') implementation
    $ic = "URI::$scheme";  # default location

    # turn scheme into a valid perl identifier by a simple transformation...
    $ic =~ s/\+/_P/g;
    $ic =~ s/\./_O/g;
    $ic =~ s/\-/_/g;

    no strict 'refs';
    # check we actually have one for the scheme:
    unless (@{"${ic}::ISA"}) {
        if (not exists $require_attempted{$ic}) {
            # Try to load it
            my $_old_error = $@;
            eval "require $ic";
            die $@ if $@ &amp;&amp; $@ !~ /Can\'t locate.*in \@INC/;
            $@ = $_old_error;
        }
        return undef unless @{"${ic}::ISA"};
    }

    $ic-&gt;_init_implementor($scheme);
    $implements{$scheme} = $ic;
    $ic;
}


sub _init_implementor
{
    my($class, $scheme) = @_;
    # Remember that one implementor class may actually
    # serve to implement several URI schemes.
}


sub clone
{
    my $self = shift;
    my $other = $$self;
    bless \$other, ref $self;
}

sub TO_JSON { ${$_[0]} }

sub _no_scheme_ok { 0 }

sub _scheme
{
    my $self = shift;

    unless (@_) {
	return undef unless $$self =~ /^($scheme_re):/o;
	return $1;
    }

    my $old;
    my $new = shift;
    if (defined($new) &amp;&amp; length($new)) {
	Carp::croak("Bad scheme '$new'") unless $new =~ /^$scheme_re$/o;
	$old = $1 if $$self =~ s/^($scheme_re)://o;
	my $newself = URI-&gt;new("$new:$$self");
	$$self = $$newself; 
	bless $self, ref($newself);
    }
    else {
	if ($self-&gt;_no_scheme_ok) {
	    $old = $1 if $$self =~ s/^($scheme_re)://o;
	    Carp::carp("Oops, opaque part now look like scheme")
		if $^W &amp;&amp; $$self =~ m/^$scheme_re:/o
	}
	else {
	    $old = $1 if $$self =~ m/^($scheme_re):/o;
	}
    }

    return $old;
}

sub scheme
{
    my $scheme = shift-&gt;_scheme(@_);
    return undef unless defined $scheme;
    lc($scheme);
}

sub has_recognized_scheme {
    my $self = shift;
    return ref($self) !~ /^URI::_(?:foreign|generic)\z/;
}

sub opaque
{
    my $self = shift;

    unless (@_) {
	$$self =~ /^(?:$scheme_re:)?([^\#]*)/o or die;
	return $1;
    }

    $$self =~ /^($scheme_re:)?    # optional scheme
	        ([^\#]*)          # opaque
                (\#.*)?           # optional fragment
              $/sx or die;

    my $old_scheme = $1;
    my $old_opaque = $2;
    my $old_frag   = $3;

    my $new_opaque = shift;
    $new_opaque = "" unless defined $new_opaque;
    $new_opaque =~ s/([^$uric])/ URI::Escape::escape_char($1)/ego;
    utf8::downgrade($new_opaque);

    $$self = defined($old_scheme) ? $old_scheme : "";
    $$self .= $new_opaque;
    $$self .= $old_frag if defined $old_frag;

    $old_opaque;
}

sub path { goto &amp;opaque }  # alias


sub fragment
{
    my $self = shift;
    unless (@_) {
	return undef unless $$self =~ /\#(.*)/s;
	return $1;
    }

    my $old;
    $old = $1 if $$self =~ s/\#(.*)//s;

    my $new_frag = shift;
    if (defined $new_frag) {
	$new_frag =~ s/([^$uric])/ URI::Escape::escape_char($1) /ego;
	utf8::downgrade($new_frag);
	$$self .= "#$new_frag";
    }
    $old;
}


sub as_string
{
    my $self = shift;
    $$self;
}


sub as_iri
{
    my $self = shift;
    my $str = $$self;
    if ($str =~ s/%([89a-fA-F][0-9a-fA-F])/chr(hex($1))/eg) {
	# All this crap because the more obvious:
	#
	#   Encode::decode("UTF-8", $str, sub { sprintf "%%%02X", shift })
	#
	# doesn't work before Encode 2.39.  Wait for a standard release
	# to bundle that version.

	require Encode;
	my $enc = Encode::find_encoding("UTF-8");
	my $u = "";
	while (length $str) {
	    $u .= $enc-&gt;decode($str, Encode::FB_QUIET());
	    if (length $str) {
		# escape next char
		$u .= URI::Escape::escape_char(substr($str, 0, 1, ""));
	    }
	}
	$str = $u;
    }
    return $str;
}


sub canonical
{
    # Make sure scheme is lowercased, that we don't escape unreserved chars,
    # and that we use upcase escape sequences.

    my $self = shift;
    my $scheme = $self-&gt;_scheme || "";
    my $uc_scheme = $scheme =~ /[A-Z]/;
    my $esc = $$self =~ /%[a-fA-F0-9]{2}/;
    return $self unless $uc_scheme || $esc;

    my $other = $self-&gt;clone;
    if ($uc_scheme) {
	$other-&gt;_scheme(lc $scheme);
    }
    if ($esc) {
	$$other =~ s{%([0-9a-fA-F]{2})}
	            { my $a = chr(hex($1));
                      $a =~ /^[$unreserved]\z/o ? $a : "%\U$1"
                    }ge;
    }
    return $other;
}

# Compare two URIs, subclasses will provide a more correct implementation
sub eq {
    my($self, $other) = @_;
    $self  = URI-&gt;new($self, $other) unless ref $self;
    $other = URI-&gt;new($other, $self) unless ref $other;
    ref($self) eq ref($other) &amp;&amp;                # same class
	$self-&gt;canonical-&gt;as_string eq $other-&gt;canonical-&gt;as_string;
}

# generic-URI transformation methods
sub abs { $_[0]; }
sub rel { $_[0]; }

sub secure { 0 }

# help out Storable
sub STORABLE_freeze {
       my($self, $cloning) = @_;
       return $$self;
}

sub STORABLE_thaw {
       my($self, $cloning, $str) = @_;
       $$self = $str;
}

1;

__END__

=head1 NAME

URI - Uniform Resource Identifiers (absolute and relative)

=head1 SYNOPSIS

 use URI ();

 $u1 = URI-&gt;new("http://www.example.com");
 $u2 = URI-&gt;new("foo", "http");
 $u3 = $u2-&gt;abs($u1);
 $u4 = $u3-&gt;clone;
 $u5 = URI-&gt;new("HTTP://WWW.example.com:80")-&gt;canonical;

 $str = $u-&gt;as_string;
 $str = "$u";

 $scheme = $u-&gt;scheme;
 $opaque = $u-&gt;opaque;
 $path   = $u-&gt;path;
 $frag   = $u-&gt;fragment;

 $u-&gt;scheme("ftp");
 $u-&gt;host("ftp.example.com");
 $u-&gt;path("cpan/");

=head1 DESCRIPTION

This module implements the C&lt;URI&gt; class.  Objects of this class
represent "Uniform Resource Identifier references" as specified in RFC
2396 (and updated by RFC 2732).

A Uniform Resource Identifier is a compact string of characters that
identifies an abstract or physical resource.  A Uniform Resource
Identifier can be further classified as either a Uniform Resource Locator
(URL) or a Uniform Resource Name (URN).  The distinction between URL
and URN does not matter to the C&lt;URI&gt; class interface. A
"URI-reference" is a URI that may have additional information attached
in the form of a fragment identifier.

An absolute URI reference consists of three parts:  a I&lt;scheme&gt;, a
I&lt;scheme-specific part&gt; and a I&lt;fragment&gt; identifier.  A subset of URI
references share a common syntax for hierarchical namespaces.  For
these, the scheme-specific part is further broken down into
I&lt;authority&gt;, I&lt;path&gt; and I&lt;query&gt; components.  These URIs can also
take the form of relative URI references, where the scheme (and
usually also the authority) component is missing, but implied by the
context of the URI reference.  The three forms of URI reference
syntax are summarized as follows:

  &lt;scheme&gt;:&lt;scheme-specific-part&gt;#&lt;fragment&gt;
  &lt;scheme&gt;://&lt;authority&gt;&lt;path&gt;?&lt;query&gt;#&lt;fragment&gt;
  &lt;path&gt;?&lt;query&gt;#&lt;fragment&gt;

The components into which a URI reference can be divided depend on the
I&lt;scheme&gt;.  The C&lt;URI&gt; class provides methods to get and set the
individual components.  The methods available for a specific
C&lt;URI&gt; object depend on the scheme.

=head1 CONSTRUCTORS

The following methods construct new C&lt;URI&gt; objects:

=over 4

=item $uri = URI-&gt;new( $str )

=item $uri = URI-&gt;new( $str, $scheme )

Constructs a new URI object.  The string
representation of a URI is given as argument, together with an optional
scheme specification.  Common URI wrappers like "" and &lt;&gt;, as well as
leading and trailing white space, are automatically removed from
the $str argument before it is processed further.

The constructor determines the scheme, maps this to an appropriate
URI subclass, constructs a new object of that class and returns it.

If the scheme isn't one of those that URI recognizes, you still get
an URI object back that you can access the generic methods on.  The
C&lt;&lt; $uri-&gt;has_recognized_scheme &gt;&gt; method can be used to test for
this.

The $scheme argument is only used when $str is a
relative URI.  It can be either a simple string that
denotes the scheme, a string containing an absolute URI reference, or
an absolute C&lt;URI&gt; object.  If no $scheme is specified for a relative
URI $str, then $str is simply treated as a generic URI (no scheme-specific
methods available).

The set of characters available for building URI references is
restricted (see L&lt;URI::Escape&gt;).  Characters outside this set are
automatically escaped by the URI constructor.

=item $uri = URI-&gt;new_abs( $str, $base_uri )

Constructs a new absolute URI object.  The $str argument can
denote a relative or absolute URI.  If relative, then it is
absolutized using $base_uri as base. The $base_uri must be an absolute
URI.

=item $uri = URI::file-&gt;new( $filename )

=item $uri = URI::file-&gt;new( $filename, $os )

Constructs a new I&lt;file&gt; URI from a file name.  See L&lt;URI::file&gt;.

=item $uri = URI::file-&gt;new_abs( $filename )

=item $uri = URI::file-&gt;new_abs( $filename, $os )

Constructs a new absolute I&lt;file&gt; URI from a file name.  See
L&lt;URI::file&gt;.

=item $uri = URI::file-&gt;cwd

Returns the current working directory as a I&lt;file&gt; URI.  See
L&lt;URI::file&gt;.

=item $uri-&gt;clone

Returns a copy of the $uri.

=back

=head1 COMMON METHODS

The methods described in this section are available for all C&lt;URI&gt;
objects.

Methods that give access to components of a URI always return the
old value of the component.  The value returned is C&lt;undef&gt; if the
component was not present.  There is generally a difference between a
component that is empty (represented as C&lt;""&gt;) and a component that is
missing (represented as C&lt;undef&gt;).  If an accessor method is given an
argument, it updates the corresponding component in addition to
returning the old value of the component.  Passing an undefined
argument removes the component (if possible).  The description of
each accessor method indicates whether the component is passed as
an escaped (percent-encoded) or an unescaped string.  A component that can be further
divided into sub-parts are usually passed escaped, as unescaping might
change its semantics.

The common methods available for all URI are:

=over 4

=item $uri-&gt;scheme

=item $uri-&gt;scheme( $new_scheme )

Sets and returns the scheme part of the $uri.  If the $uri is
relative, then $uri-&gt;scheme returns C&lt;undef&gt;.  If called with an
argument, it updates the scheme of $uri, possibly changing the
class of $uri, and returns the old scheme value.  The method croaks
if the new scheme name is illegal; a scheme name must begin with a
letter and must consist of only US-ASCII letters, numbers, and a few
special marks: ".", "+", "-".  This restriction effectively means
that the scheme must be passed unescaped.  Passing an undefined
argument to the scheme method makes the URI relative (if possible).

Letter case does not matter for scheme names.  The string
returned by $uri-&gt;scheme is always lowercase.  If you want the scheme
just as it was written in the URI in its original case,
you can use the $uri-&gt;_scheme method instead.

=item $uri-&gt;has_recognized_scheme

Returns TRUE if the URI scheme is one that URI recognizes.

It will also be TRUE for relative URLs where a recognized
scheme was provided to the constructor, even if C&lt;&lt; $uri-&gt;scheme &gt;&gt;
returns C&lt;undef&gt; for these.

=item $uri-&gt;opaque

=item $uri-&gt;opaque( $new_opaque )

Sets and returns the scheme-specific part of the $uri
(everything between the scheme and the fragment)
as an escaped string.

=item $uri-&gt;path

=item $uri-&gt;path( $new_path )

Sets and returns the same value as $uri-&gt;opaque unless the URI
supports the generic syntax for hierarchical namespaces.
In that case the generic method is overridden to set and return
the part of the URI between the I&lt;host name&gt; and the I&lt;fragment&gt;.

=item $uri-&gt;fragment

=item $uri-&gt;fragment( $new_frag )

Returns the fragment identifier of a URI reference
as an escaped string.

=item $uri-&gt;as_string

Returns a URI object to a plain ASCII string.  URI objects are
also converted to plain strings automatically by overloading.  This
means that $uri objects can be used as plain strings in most Perl
constructs.

=item $uri-&gt;as_iri

Returns a Unicode string representing the URI.  Escaped UTF-8 sequences
representing non-ASCII characters are turned into their corresponding Unicode
code point.

=item $uri-&gt;canonical

Returns a normalized version of the URI.  The rules
for normalization are scheme-dependent.  They usually involve
lowercasing the scheme and Internet host name components,
removing the explicit port specification if it matches the default port,
uppercasing all escape sequences, and unescaping octets that can be
better represented as plain characters.

For efficiency reasons, if the $uri is already in normalized form,
then a reference to it is returned instead of a copy.

=item $uri-&gt;eq( $other_uri )

=item URI::eq( $first_uri, $other_uri )

Tests whether two URI references are equal.  URI references
that normalize to the same string are considered equal.  The method
can also be used as a plain function which can also test two string
arguments.

If you need to test whether two C&lt;URI&gt; object references denote the
same object, use the '==' operator.

=item $uri-&gt;abs( $base_uri )

Returns an absolute URI reference.  If $uri is already
absolute, then a reference to it is simply returned.  If the $uri
is relative, then a new absolute URI is constructed by combining the
$uri and the $base_uri, and returned.

=item $uri-&gt;rel( $base_uri )

Returns a relative URI reference if it is possible to
make one that denotes the same resource relative to $base_uri.
If not, then $uri is simply returned.

=item $uri-&gt;secure

Returns a TRUE value if the URI is considered to point to a resource on
a secure channel, such as an SSL or TLS encrypted one.

=back

=head1 GENERIC METHODS

The following methods are available to schemes that use the
common/generic syntax for hierarchical namespaces.  The descriptions of
schemes below indicate which these are.  Unrecognized schemes are
assumed to support the generic syntax, and therefore the following
methods:

=over 4

=item $uri-&gt;authority

=item $uri-&gt;authority( $new_authority )

Sets and returns the escaped authority component
of the $uri.

=item $uri-&gt;path

=item $uri-&gt;path( $new_path )

Sets and returns the escaped path component of
the $uri (the part between the host name and the query or fragment).
The path can never be undefined, but it can be the empty string.

=item $uri-&gt;path_query

=item $uri-&gt;path_query( $new_path_query )

Sets and returns the escaped path and query
components as a single entity.  The path and the query are
separated by a "?" character, but the query can itself contain "?".

=item $uri-&gt;path_segments

=item $uri-&gt;path_segments( $segment, ... )

Sets and returns the path.  In a scalar context, it returns
the same value as $uri-&gt;path.  In a list context, it returns the
unescaped path segments that make up the path.  Path segments that
have parameters are returned as an anonymous array.  The first element
is the unescaped path segment proper;  subsequent elements are escaped
parameter strings.  Such an anonymous array uses overloading so it can
be treated as a string too, but this string does not include the
parameters.

Note that absolute paths have the empty string as their first
I&lt;path_segment&gt;, i.e. the I&lt;path&gt; C&lt;/foo/bar&gt; have 3
I&lt;path_segments&gt;; "", "foo" and "bar".

=item $uri-&gt;query

=item $uri-&gt;query( $new_query )

Sets and returns the escaped query component of
the $uri.

=item $uri-&gt;query_form

=item $uri-&gt;query_form( $key1 =&gt; $val1, $key2 =&gt; $val2, ... )

=item $uri-&gt;query_form( $key1 =&gt; $val1, $key2 =&gt; $val2, ..., $delim )

=item $uri-&gt;query_form( \@key_value_pairs )

=item $uri-&gt;query_form( \@key_value_pairs, $delim )

=item $uri-&gt;query_form( \%hash )

=item $uri-&gt;query_form( \%hash, $delim )

Sets and returns query components that use the
I&lt;application/x-www-form-urlencoded&gt; format.  Key/value pairs are
separated by "&amp;", and the key is separated from the value by a "="
character.

The form can be set either by passing separate key/value pairs, or via
an array or hash reference.  Passing an empty array or an empty hash
removes the query component, whereas passing no arguments at all leaves
the component unchanged.  The order of keys is undefined if a hash
reference is passed.  The old value is always returned as a list of
separate key/value pairs.  Assigning this list to a hash is unwise as
the keys returned might repeat.

The values passed when setting the form can be plain strings or
references to arrays of strings.  Passing an array of values has the
same effect as passing the key repeatedly with one value at a time.
All the following statements have the same effect:

    $uri-&gt;query_form(foo =&gt; 1, foo =&gt; 2);
    $uri-&gt;query_form(foo =&gt; [1, 2]);
    $uri-&gt;query_form([ foo =&gt; 1, foo =&gt; 2 ]);
    $uri-&gt;query_form([ foo =&gt; [1, 2] ]);
    $uri-&gt;query_form({ foo =&gt; [1, 2] });

The $delim parameter can be passed as ";" to force the key/value pairs
to be delimited by ";" instead of "&amp;" in the query string.  This
practice is often recommended for URLs embedded in HTML or XML
documents as this avoids the trouble of escaping the "&amp;" character.
You might also set the $URI::DEFAULT_QUERY_FORM_DELIMITER variable to
";" for the same global effect.

The C&lt;URI::QueryParam&gt; module can be loaded to add further methods to
manipulate the form of a URI.  See L&lt;URI::QueryParam&gt; for details.

=item $uri-&gt;query_keywords

=item $uri-&gt;query_keywords( $keywords, ... )

=item $uri-&gt;query_keywords( \@keywords )

Sets and returns query components that use the
keywords separated by "+" format.

The keywords can be set either by passing separate keywords directly
or by passing a reference to an array of keywords.  Passing an empty
array removes the query component, whereas passing no arguments at
all leaves the component unchanged.  The old value is always returned
as a list of separate words.

=back

=head1 SERVER METHODS

For schemes where the I&lt;authority&gt; component denotes an Internet host,
the following methods are available in addition to the generic
methods.

=over 4

=item $uri-&gt;userinfo

=item $uri-&gt;userinfo( $new_userinfo )

Sets and returns the escaped userinfo part of the
authority component.

For some schemes this is a user name and a password separated by
a colon.  This practice is not recommended. Embedding passwords in
clear text (such as URI) has proven to be a security risk in almost
every case where it has been used.

=item $uri-&gt;host

=item $uri-&gt;host( $new_host )

Sets and returns the unescaped hostname.

If the $new_host string ends with a colon and a number, then this
number also sets the port.

For IPv6 addresses the brackets around the raw address is removed in the return
value from $uri-&gt;host.  When setting the host attribute to an IPv6 address you
can use a raw address or one enclosed in brackets.  The address needs to be
enclosed in brackets if you want to pass in a new port value as well.

=item $uri-&gt;ihost

Returns the host in Unicode form.  Any IDNA A-labels are turned into U-labels.

=item $uri-&gt;port

=item $uri-&gt;port( $new_port )

Sets and returns the port.  The port is a simple integer
that should be greater than 0.

If a port is not specified explicitly in the URI, then the URI scheme's default port
is returned. If you don't want the default port
substituted, then you can use the $uri-&gt;_port method instead.

=item $uri-&gt;host_port

=item $uri-&gt;host_port( $new_host_port )

Sets and returns the host and port as a single
unit.  The returned value includes a port, even if it matches the
default port.  The host part and the port part are separated by a
colon: ":".

For IPv6 addresses the bracketing is preserved; thus
URI-&gt;new("http://[::1]/")-&gt;host_port returns "[::1]:80".  Contrast this with
$uri-&gt;host which will remove the brackets.

=item $uri-&gt;default_port

Returns the default port of the URI scheme to which $uri
belongs.  For I&lt;http&gt; this is the number 80, for I&lt;ftp&gt; this
is the number 21, etc.  The default port for a scheme can not be
changed.

=back

=head1 SCHEME-SPECIFIC SUPPORT

Scheme-specific support is provided for the following URI schemes.  For C&lt;URI&gt;
objects that do not belong to one of these, you can only use the common and
generic methods.

=over 4

=item B&lt;data&gt;:

The I&lt;data&gt; URI scheme is specified in RFC 2397.  It allows inclusion
of small data items as "immediate" data, as if it had been included
externally.

C&lt;URI&gt; objects belonging to the data scheme support the common methods
and two new methods to access their scheme-specific components:
$uri-&gt;media_type and $uri-&gt;data.  See L&lt;URI::data&gt; for details.

=item B&lt;file&gt;:

An old specification of the I&lt;file&gt; URI scheme is found in RFC 1738.
A new RFC 2396 based specification in not available yet, but file URI
references are in common use.

C&lt;URI&gt; objects belonging to the file scheme support the common and
generic methods.  In addition, they provide two methods for mapping file URIs
back to local file names; $uri-&gt;file and $uri-&gt;dir.  See L&lt;URI::file&gt;
for details.

=item B&lt;ftp&gt;:

An old specification of the I&lt;ftp&gt; URI scheme is found in RFC 1738.  A
new RFC 2396 based specification in not available yet, but ftp URI
references are in common use.

C&lt;URI&gt; objects belonging to the ftp scheme support the common,
generic and server methods.  In addition, they provide two methods for
accessing the userinfo sub-components: $uri-&gt;user and $uri-&gt;password.

=item B&lt;gopher&gt;:

The I&lt;gopher&gt; URI scheme is specified in
&lt;draft-murali-url-gopher-1996-12-04&gt; and will hopefully be available
as a RFC 2396 based specification.

C&lt;URI&gt; objects belonging to the gopher scheme support the common,
generic and server methods. In addition, they support some methods for
accessing gopher-specific path components: $uri-&gt;gopher_type,
$uri-&gt;selector, $uri-&gt;search, $uri-&gt;string.

=item B&lt;http&gt;:

The I&lt;http&gt; URI scheme is specified in RFC 2616.
The scheme is used to reference resources hosted by HTTP servers.

C&lt;URI&gt; objects belonging to the http scheme support the common,
generic and server methods.

=item B&lt;https&gt;:

The I&lt;https&gt; URI scheme is a Netscape invention which is commonly
implemented.  The scheme is used to reference HTTP servers through SSL
connections.  Its syntax is the same as http, but the default
port is different.

=item B&lt;ldap&gt;:

The I&lt;ldap&gt; URI scheme is specified in RFC 2255.  LDAP is the
Lightweight Directory Access Protocol.  An ldap URI describes an LDAP
search operation to perform to retrieve information from an LDAP
directory.

C&lt;URI&gt; objects belonging to the ldap scheme support the common,
generic and server methods as well as ldap-specific methods: $uri-&gt;dn,
$uri-&gt;attributes, $uri-&gt;scope, $uri-&gt;filter, $uri-&gt;extensions.  See
L&lt;URI::ldap&gt; for details.

=item B&lt;ldapi&gt;:

Like the I&lt;ldap&gt; URI scheme, but uses a UNIX domain socket.  The
server methods are not supported, and the local socket path is
available as $uri-&gt;un_path.  The I&lt;ldapi&gt; scheme is used by the
OpenLDAP package.  There is no real specification for it, but it is
mentioned in various OpenLDAP manual pages.

=item B&lt;ldaps&gt;:

Like the I&lt;ldap&gt; URI scheme, but uses an SSL connection.  This
scheme is deprecated, as the preferred way is to use the I&lt;start_tls&gt;
mechanism.

=item B&lt;mailto&gt;:

The I&lt;mailto&gt; URI scheme is specified in RFC 2368.  The scheme was
originally used to designate the Internet mailing address of an
individual or service.  It has (in RFC 2368) been extended to allow
setting of other mail header fields and the message body.

C&lt;URI&gt; objects belonging to the mailto scheme support the common
methods and the generic query methods.  In addition, they support the
following mailto-specific methods: $uri-&gt;to, $uri-&gt;headers.

Note that the "foo@example.com" part of a mailto is I&lt;not&gt; the
C&lt;userinfo&gt; and C&lt;host&gt; but instead the C&lt;path&gt;.  This allows a
mailto URI to contain multiple comma separated email addresses.

=item B&lt;mms&gt;:

The I&lt;mms&gt; URL specification can be found at L&lt;http://sdp.ppona.com/&gt;.
C&lt;URI&gt; objects belonging to the mms scheme support the common,
generic, and server methods, with the exception of userinfo and
query-related sub-components.

=item B&lt;news&gt;:

The I&lt;news&gt;, I&lt;nntp&gt; and I&lt;snews&gt; URI schemes are specified in
&lt;draft-gilman-news-url-01&gt; and will hopefully be available as an RFC
2396 based specification soon. (Update: as of April 2010, they are in
L&lt;RFC 5538|https://tools.ietf.org/html/rfc5538&gt;.

C&lt;URI&gt; objects belonging to the news scheme support the common,
generic and server methods.  In addition, they provide some methods to
access the path: $uri-&gt;group and $uri-&gt;message.

=item B&lt;nntp&gt;:

See I&lt;news&gt; scheme.

=item B&lt;nntps&gt;:

See I&lt;news&gt; scheme and L&lt;RFC 5538|https://tools.ietf.org/html/rfc5538&gt;.

=item B&lt;pop&gt;:

The I&lt;pop&gt; URI scheme is specified in RFC 2384. The scheme is used to
reference a POP3 mailbox.

C&lt;URI&gt; objects belonging to the pop scheme support the common, generic
and server methods.  In addition, they provide two methods to access the
userinfo components: $uri-&gt;user and $uri-&gt;auth

=item B&lt;rlogin&gt;:

An old specification of the I&lt;rlogin&gt; URI scheme is found in RFC
1738. C&lt;URI&gt; objects belonging to the rlogin scheme support the
common, generic and server methods.

=item B&lt;rtsp&gt;:

The I&lt;rtsp&gt; URL specification can be found in section 3.2 of RFC 2326.
C&lt;URI&gt; objects belonging to the rtsp scheme support the common,
generic, and server methods, with the exception of userinfo and
query-related sub-components.

=item B&lt;rtspu&gt;:

The I&lt;rtspu&gt; URI scheme is used to talk to RTSP servers over UDP
instead of TCP.  The syntax is the same as rtsp.

=item B&lt;rsync&gt;:

Information about rsync is available from L&lt;http://rsync.samba.org/&gt;.
C&lt;URI&gt; objects belonging to the rsync scheme support the common,
generic and server methods.  In addition, they provide methods to
access the userinfo sub-components: $uri-&gt;user and $uri-&gt;password.

=item B&lt;sip&gt;:

The I&lt;sip&gt; URI specification is described in sections 19.1 and 25
of RFC 3261.  C&lt;URI&gt; objects belonging to the sip scheme support the
common, generic, and server methods with the exception of path related
sub-components.  In addition, they provide two methods to get and set
I&lt;sip&gt; parameters: $uri-&gt;params_form and $uri-&gt;params.

=item B&lt;sips&gt;:

See I&lt;sip&gt; scheme.  Its syntax is the same as sip, but the default
port is different.

=item B&lt;snews&gt;:

See I&lt;news&gt; scheme.  Its syntax is the same as news, but the default
port is different.

=item B&lt;telnet&gt;:

An old specification of the I&lt;telnet&gt; URI scheme is found in RFC
1738. C&lt;URI&gt; objects belonging to the telnet scheme support the
common, generic and server methods.

=item B&lt;tn3270&gt;:

These URIs are used like I&lt;telnet&gt; URIs but for connections to IBM
mainframes.  C&lt;URI&gt; objects belonging to the tn3270 scheme support the
common, generic and server methods.

=item B&lt;ssh&gt;:

Information about ssh is available at L&lt;http://www.openssh.com/&gt;.
C&lt;URI&gt; objects belonging to the ssh scheme support the common,
generic and server methods. In addition, they provide methods to
access the userinfo sub-components: $uri-&gt;user and $uri-&gt;password.

=item B&lt;sftp&gt;:

C&lt;URI&gt; objects belonging to the sftp scheme support the common,
generic and server methods. In addition, they provide methods to
access the userinfo sub-components: $uri-&gt;user and $uri-&gt;password.

=item B&lt;urn&gt;:

The syntax of Uniform Resource Names is specified in RFC 2141.  C&lt;URI&gt;
objects belonging to the urn scheme provide the common methods, and also the
methods $uri-&gt;nid and $uri-&gt;nss, which return the Namespace Identifier
and the Namespace-Specific String respectively.

The Namespace Identifier basically works like the Scheme identifier of
URIs, and further divides the URN namespace.  Namespace Identifier
assignments are maintained at
L&lt;http://www.iana.org/assignments/urn-namespaces&gt;.

Letter case is not significant for the Namespace Identifier.  It is
always returned in lower case by the $uri-&gt;nid method.  The $uri-&gt;_nid
method can be used if you want it in its original case.

=item B&lt;urn&gt;:B&lt;isbn&gt;:

The C&lt;urn:isbn:&gt; namespace contains International Standard Book
Numbers (ISBNs) and is described in RFC 3187.  A C&lt;URI&gt; object belonging
to this namespace has the following extra methods (if the
Business::ISBN module is available): $uri-&gt;isbn,
$uri-&gt;isbn_publisher_code, $uri-&gt;isbn_group_code (formerly isbn_country_code,
which is still supported by issues a deprecation warning), $uri-&gt;isbn_as_ean.

=item B&lt;urn&gt;:B&lt;oid&gt;:

The C&lt;urn:oid:&gt; namespace contains Object Identifiers (OIDs) and is
described in RFC 3061.  An object identifier consists of sequences of digits
separated by dots.  A C&lt;URI&gt; object belonging to this namespace has an
additional method called $uri-&gt;oid that can be used to get/set the oid
value.  In a list context, oid numbers are returned as separate elements.

=back

=head1 CONFIGURATION VARIABLES

The following configuration variables influence how the class and its
methods behave:

=over 4

=item $URI::ABS_ALLOW_RELATIVE_SCHEME

Some older parsers used to allow the scheme name to be present in the
relative URL if it was the same as the base URL scheme.  RFC 2396 says
that this should be avoided, but you can enable this old behaviour by
setting the $URI::ABS_ALLOW_RELATIVE_SCHEME variable to a TRUE value.
The difference is demonstrated by the following examples:

  URI-&gt;new("http:foo")-&gt;abs("http://host/a/b")
      ==&gt;  "http:foo"

  local $URI::ABS_ALLOW_RELATIVE_SCHEME = 1;
  URI-&gt;new("http:foo")-&gt;abs("http://host/a/b")
      ==&gt;  "http:/host/a/foo"


=item $URI::ABS_REMOTE_LEADING_DOTS

You can also have the abs() method ignore excess ".."
segments in the relative URI by setting $URI::ABS_REMOTE_LEADING_DOTS
to a TRUE value.  The difference is demonstrated by the following
examples:

  URI-&gt;new("../../../foo")-&gt;abs("http://host/a/b")
      ==&gt; "http://host/../../foo"

  local $URI::ABS_REMOTE_LEADING_DOTS = 1;
  URI-&gt;new("../../../foo")-&gt;abs("http://host/a/b")
      ==&gt; "http://host/foo"

=item $URI::DEFAULT_QUERY_FORM_DELIMITER

This value can be set to ";" to have the query form C&lt;key=value&gt; pairs
delimited by ";" instead of "&amp;" which is the default.

=back

=head1 BUGS

There are some things that are not quite right:

=over

=item *

Using regexp variables like $1 directly as arguments to the URI accessor methods
does not work too well with current perl implementations.  I would argue
that this is actually a bug in perl.  The workaround is to quote
them. Example:

   /(...)/ || die;
   $u-&gt;query("$1");


=item *

The escaping (percent encoding) of chars in the 128 .. 255 range passed to the
URI constructor or when setting URI parts using the accessor methods depend on
the state of the internal UTF8 flag (see utf8::is_utf8) of the string passed.
If the UTF8 flag is set the UTF-8 encoded version of the character is percent
encoded.  If the UTF8 flag isn't set the Latin-1 version (byte) of the
character is percent encoded.  This basically exposes the internal encoding of
Perl strings.

=back

=head1 PARSING URIs WITH REGEXP

As an alternative to this module, the following (official) regular
expression can be used to decode a URI:

  my($scheme, $authority, $path, $query, $fragment) =
  $uri =~ m|(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?|;

The C&lt;URI::Split&gt; module provides the function uri_split() as a
readable alternative.

=head1 SEE ALSO

L&lt;URI::file&gt;, L&lt;URI::WithBase&gt;, L&lt;URI::QueryParam&gt;, L&lt;URI::Escape&gt;,
L&lt;URI::Split&gt;, L&lt;URI::Heuristic&gt;

RFC 2396: "Uniform Resource Identifiers (URI): Generic Syntax",
Berners-Lee, Fielding, Masinter, August 1998.

L&lt;http://www.iana.org/assignments/uri-schemes&gt;

L&lt;http://www.iana.org/assignments/urn-namespaces&gt;

L&lt;http://www.w3.org/Addressing/&gt;

=head1 COPYRIGHT

Copyright 1995-2009 Gisle Aas.

Copyright 1995 Martijn Koster.

This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=head1 AUTHORS / ACKNOWLEDGMENTS

This module is based on the C&lt;URI::URL&gt; module, which in turn was
(distantly) based on the C&lt;wwwurl.pl&gt; code in the libwww-perl for
perl4 developed by Roy Fielding, as part of the Arcadia project at the
University of California, Irvine, with contributions from Brooks
Cutter.

C&lt;URI::URL&gt; was developed by Gisle Aas, Tim Bunce, Roy Fielding and
Martijn Koster with input from other people on the libwww-perl mailing
list.

C&lt;URI&gt; and related subclasses was developed by Gisle Aas.

=cut
</pre></body></html>