5 $VERSION = "1.35"; # $Date: 2004/11/05 14:17:33 $
7 use vars qw($ABS_REMOTE_LEADING_DOTS $ABS_ALLOW_RELATIVE_SCHEME);
9 my %implements; # mapping from scheme to implementor class
11 # Some "official" character classes
13 use vars qw($reserved $mark $unreserved $uric $scheme_re);
14 $reserved = q(;/?:@&=+$,[]);
15 $mark = q(-_.!~*'()); #'; emacs
16 $unreserved = "A-Za-z0-9\Q$mark\E";
17 $uric = quotemeta($reserved) . $unreserved . "%";
19 $scheme_re = '[a-zA-Z][a-zA-Z0-9.+\-]*';
24 use overload ('""' => sub { ${$_[0]} },
25 '==' => sub { overload::StrVal($_[0]) eq
26 overload::StrVal($_[1])
33 my($class, $uri, $scheme) = @_;
35 $uri = defined ($uri) ? "$uri" : ""; # stringify
36 # Get rid of potential wrapping
37 $uri =~ s/^<(?:URL:)?(.*)>$/$1/; #
38 $uri =~ s/^"(.*)"$/$1/;
43 if ($uri =~ m/^($scheme_re):/so) {
47 if (($impclass = ref($scheme))) {
48 $scheme = $scheme->scheme;
50 elsif ($scheme && $scheme =~ m/^($scheme_re)(?::|$)/o) {
54 $impclass ||= implementor($scheme) ||
56 require URI::_foreign;
57 $impclass = 'URI::_foreign';
60 return $impclass->_init($uri, $scheme);
66 my($class, $uri, $base) = @_;
67 $uri = $class->new($uri, $base);
75 my($str, $scheme) = @_;
76 $str =~ s/([^$uric\#])/$URI::Escape::escapes{$1}/go;
77 $str = "$scheme:$str" unless $str =~ /^$scheme_re:/o ||
78 $class->_no_scheme_ok;
79 my $self = bless \$str, $class;
86 my($scheme, $impclass) = @_;
87 if (!$scheme || $scheme !~ /\A$scheme_re\z/o) {
88 require URI::_generic;
89 return "URI::_generic";
92 $scheme = lc($scheme);
95 # Set the implementor class for a given scheme
96 my $old = $implements{$scheme};
97 $impclass->_init_implementor($scheme);
98 $implements{$scheme} = $impclass;
102 my $ic = $implements{$scheme};
105 # scheme not yet known, look for internal or
106 # preloaded (with 'use') implementation
107 $ic = "URI::$scheme"; # default location
109 # turn scheme into a valid perl identifier by a simple tranformation...
115 # check we actually have one for the scheme:
116 unless (@{"${ic}::ISA"}) {
119 die $@ if $@ && $@ !~ /Can\'t locate.*in \@INC/;
120 return unless @{"${ic}::ISA"};
123 $ic->_init_implementor($scheme);
124 $implements{$scheme} = $ic;
129 sub _init_implementor
131 my($class, $scheme) = @_;
132 # Remember that one implementor class may actually
133 # serve to implement several URI schemes.
141 bless \$other, ref $self;
145 sub _no_scheme_ok { 0 }
152 return unless $$self =~ /^($scheme_re):/o;
158 if (defined($new) && length($new)) {
159 Carp::croak("Bad scheme '$new'") unless $new =~ /^$scheme_re$/o;
160 $old = $1 if $$self =~ s/^($scheme_re)://o;
161 my $newself = URI->new("$new:$$self");
163 bless $self, ref($newself);
166 if ($self->_no_scheme_ok) {
167 $old = $1 if $$self =~ s/^($scheme_re)://o;
168 Carp::carp("Oops, opaque part now look like scheme")
169 if $^W && $$self =~ m/^$scheme_re:/o
172 $old = $1 if $$self =~ m/^($scheme_re):/o;
181 my $scheme = shift->_scheme(@_);
182 return unless defined $scheme;
192 $$self =~ /^(?:$scheme_re:)?([^\#]*)/o or die;
196 $$self =~ /^($scheme_re:)? # optional scheme
198 (\#.*)? # optional fragment
205 my $new_opaque = shift;
206 $new_opaque = "" unless defined $new_opaque;
207 $new_opaque =~ s/([^$uric])/$URI::Escape::escapes{$1}/go;
209 $$self = defined($old_scheme) ? $old_scheme : "";
210 $$self .= $new_opaque;
211 $$self .= $old_frag if defined $old_frag;
216 *path = \&opaque; # alias
223 return unless $$self =~ /\#(.*)/s;
228 $old = $1 if $$self =~ s/\#(.*)//s;
230 my $new_frag = shift;
231 if (defined $new_frag) {
232 $new_frag =~ s/([^$uric])/$URI::Escape::escapes{$1}/go;
233 $$self .= "#$new_frag";
248 # Make sure scheme is lowercased, that we don't escape unreserved chars,
249 # and that we use upcase escape sequences.
252 my $scheme = $self->_scheme || "";
253 my $uc_scheme = $scheme =~ /[A-Z]/;
254 my $esc = $$self =~ /%[a-fA-F0-9]{2}/;
255 return $self unless $uc_scheme || $esc;
257 my $other = $self->clone;
259 $other->_scheme(lc $scheme);
262 $$other =~ s{%([0-9a-fA-F]{2})}
263 { my $a = chr(hex($1));
264 $a =~ /^[$unreserved]\z/o ? $a : "%\U$1"
270 # Compare two URIs, subclasses will provide a more correct implementation
272 my($self, $other) = @_;
273 $self = URI->new($self, $other) unless ref $self;
274 $other = URI->new($other, $self) unless ref $other;
275 ref($self) eq ref($other) && # same class
276 $self->canonical->as_string eq $other->canonical->as_string;
279 # generic-URI transformation methods
284 sub STORABLE_freeze {
285 my($self, $cloning) = @_;
290 my($self, $cloning, $str) = @_;
300 URI - Uniform Resource Identifiers (absolute and relative)
304 $u1 = URI->new("http://www.perl.com");
305 $u2 = URI->new("foo", "http");
308 $u5 = URI->new("HTTP://WWW.perl.com:80")->canonical;
310 $str = $u->as_string;
313 $scheme = $u->scheme;
314 $opaque = $u->opaque;
316 $frag = $u->fragment;
319 $u->host("ftp.perl.com");
324 This module implements the C<URI> class. Objects of this class
325 represent "Uniform Resource Identifier references" as specified in RFC
326 2396 (and updated by RFC 2732).
328 A Uniform Resource Identifier is a compact string of characters that
329 identifies an abstract or physical resource. A Uniform Resource
330 Identifier can be further classified as either a Uniform Resource Locator
331 (URL) or a Uniform Resource Name (URN). The distinction between URL
332 and URN does not matter to the C<URI> class interface. A
333 "URI-reference" is a URI that may have additional information attached
334 in the form of a fragment identifier.
336 An absolute URI reference consists of three parts: a I<scheme>, a
337 I<scheme-specific part> and a I<fragment> identifier. A subset of URI
338 references share a common syntax for hierarchical namespaces. For
339 these, the scheme-specific part is further broken down into
340 I<authority>, I<path> and I<query> components. These URIs can also
341 take the form of relative URI references, where the scheme (and
342 usually also the authority) component is missing, but implied by the
343 context of the URI reference. The three forms of URI reference
344 syntax are summarized as follows:
346 <scheme>:<scheme-specific-part>#<fragment>
347 <scheme>://<authority><path>?<query>#<fragment>
348 <path>?<query>#<fragment>
350 The components into which a URI reference can be divided depend on the
351 I<scheme>. The C<URI> class provides methods to get and set the
352 individual components. The methods available for a specific
353 C<URI> object depend on the scheme.
357 The following methods construct new C<URI> objects:
361 =item $uri = URI->new( $str )
363 =item $uri = URI->new( $str, $scheme )
365 Constructs a new URI object. The string
366 representation of a URI is given as argument, together with an optional
367 scheme specification. Common URI wrappers like "" and <>, as well as
368 leading and trailing white space, are automatically removed from
369 the $str argument before it is processed further.
371 The constructor determines the scheme, maps this to an appropriate
372 URI subclass, constructs a new object of that class and returns it.
374 The $scheme argument is only used when $str is a
375 relative URI. It can be either a simple string that
376 denotes the scheme, a string containing an absolute URI reference, or
377 an absolute C<URI> object. If no $scheme is specified for a relative
378 URI $str, then $str is simply treated as a generic URI (no scheme-specific
381 The set of characters available for building URI references is
382 restricted (see L<URI::Escape>). Characters outside this set are
383 automatically escaped by the URI constructor.
385 =item $uri = URI->new_abs( $str, $base_uri )
387 Constructs a new absolute URI object. The $str argument can
388 denote a relative or absolute URI. If relative, then it is
389 absolutized using $base_uri as base. The $base_uri must be an absolute
392 =item $uri = URI::file->new( $filename )
394 =item $uri = URI::file->new( $filename, $os )
396 Constructs a new I<file> URI from a file name. See L<URI::file>.
398 =item $uri = URI::file->new_abs( $filename )
400 =item $uri = URI::file->new_abs( $filename, $os )
402 Constructs a new absolute I<file> URI from a file name. See
405 =item $uri = URI::file->cwd
407 Returns the current working directory as a I<file> URI. See
412 Returns a copy of the $uri.
416 =head1 COMMON METHODS
418 The methods described in this section are available for all C<URI>
421 Methods that give access to components of a URI always return the
422 old value of the component. The value returned is C<undef> if the
423 component was not present. There is generally a difference between a
424 component that is empty (represented as C<"">) and a component that is
425 missing (represented as C<undef>). If an accessor method is given an
426 argument, it updates the corresponding component in addition to
427 returning the old value of the component. Passing an undefined
428 argument removes the component (if possible). The description of
429 each accessor method indicates whether the component is passed as
430 an escaped or an unescaped string. A component that can be further
431 divided into sub-parts are usually passed escaped, as unescaping might
432 change its semantics.
434 The common methods available for all URI are:
440 =item $uri->scheme( $new_scheme )
442 Sets and returns the scheme part of the $uri. If the $uri is
443 relative, then $uri->scheme returns C<undef>. If called with an
444 argument, it updates the scheme of $uri, possibly changing the
445 class of $uri, and returns the old scheme value. The method croaks
446 if the new scheme name is illegal; a scheme name must begin with a
447 letter and must consist of only US-ASCII letters, numbers, and a few
448 special marks: ".", "+", "-". This restriction effectively means
449 that the scheme must be passed unescaped. Passing an undefined
450 argument to the scheme method makes the URI relative (if possible).
452 Letter case does not matter for scheme names. The string
453 returned by $uri->scheme is always lowercase. If you want the scheme
454 just as it was written in the URI in its original case,
455 you can use the $uri->_scheme method instead.
459 =item $uri->opaque( $new_opaque )
461 Sets and returns the scheme-specific part of the $uri
462 (everything between the scheme and the fragment)
463 as an escaped string.
467 =item $uri->path( $new_path )
469 Sets and returns the same value as $uri->opaque unless the URI
470 supports the generic syntax for hierarchical namespaces.
471 In that case the generic method is overridden to set and return
472 the part of the URI between the I<host name> and the I<fragment>.
476 =item $uri->fragment( $new_frag )
478 Returns the fragment identifier of a URI reference
479 as an escaped string.
481 =item $uri->as_string
483 Returns a URI object to a plain string. URI objects are
484 also converted to plain strings automatically by overloading. This
485 means that $uri objects can be used as plain strings in most Perl
488 =item $uri->canonical
490 Returns a normalized version of the URI. The rules
491 for normalization are scheme-dependent. They usually involve
492 lowercasing the scheme and Internet host name components,
493 removing the explicit port specification if it matches the default port,
494 uppercasing all escape sequences, and unescaping octets that can be
495 better represented as plain characters.
497 For efficiency reasons, if the $uri is already in normalized form,
498 then a reference to it is returned instead of a copy.
500 =item $uri->eq( $other_uri )
502 =item URI::eq( $first_uri, $other_uri )
504 Tests whether two URI references are equal. URI references
505 that normalize to the same string are considered equal. The method
506 can also be used as a plain function which can also test two string
509 If you need to test whether two C<URI> object references denote the
510 same object, use the '==' operator.
512 =item $uri->abs( $base_uri )
514 Returns an absolute URI reference. If $uri is already
515 absolute, then a reference to it is simply returned. If the $uri
516 is relative, then a new absolute URI is constructed by combining the
517 $uri and the $base_uri, and returned.
519 =item $uri->rel( $base_uri )
521 Returns a relative URI reference if it is possible to
522 make one that denotes the same resource relative to $base_uri.
523 If not, then $uri is simply returned.
527 =head1 GENERIC METHODS
529 The following methods are available to schemes that use the
530 common/generic syntax for hierarchical namespaces. The descriptions of
531 schemes below indicate which these are. Unknown schemes are
532 assumed to support the generic syntax, and therefore the following
537 =item $uri->authority
539 =item $uri->authority( $new_authority )
541 Sets and returns the escaped authority component
546 =item $uri->path( $new_path )
548 Sets and returns the escaped path component of
549 the $uri (the part between the host name and the query or fragment).
550 The path can never be undefined, but it can be the empty string.
552 =item $uri->path_query
554 =item $uri->path_query( $new_path_query )
556 Sets and returns the escaped path and query
557 components as a single entity. The path and the query are
558 separated by a "?" character, but the query can itself contain "?".
560 =item $uri->path_segments
562 =item $uri->path_segments( $segment, ... )
564 Sets and returns the path. In a scalar context, it returns
565 the same value as $uri->path. In a list context, it returns the
566 unescaped path segments that make up the path. Path segments that
567 have parameters are returned as an anonymous array. The first element
568 is the unescaped path segment proper; subsequent elements are escaped
569 parameter strings. Such an anonymous array uses overloading so it can
570 be treated as a string too, but this string does not include the
573 Note that absolute paths have the empty string as their first
574 I<path_segment>, i.e. the I<path> C</foo/bar> have 3
575 I<path_segments>; "", "foo" and "bar".
579 =item $uri->query( $new_query )
581 Sets and returns the escaped query component of
584 =item $uri->query_form
586 =item $uri->query_form( $key1 => $val1, $key2 => $val2, ... )
588 =item $uri->query_form( \@key_value_pairs )
590 =item $uri->query_form( \%hash )
592 Sets and returns query components that use the
593 I<application/x-www-form-urlencoded> format. Key/value pairs are
594 separated by "&", and the key is separated from the value by a "="
597 The form can be set either by passing separate key/value pairs, or via
598 an array or hash reference. Passing an empty array or an empty hash
599 removes the query component, whereas passing no arguments at all leaves
600 the component unchanged. The order of keys is undefined if a hash
601 reference is passed. The old value is always returned as a list of
602 separate key/value pairs. Assigning this list to a hash is unwise as
603 the keys returned might repeat.
605 The values passed when setting the form can be plain strings or
606 references to arrays of strings. Passing an array of values has the
607 same effect as passing the key repeatedly with one value at a time.
608 All the following statements have the same effect:
610 $uri->query_form(foo => 1, foo => 2);
611 $uri->query_form(foo => [1, 2]);
612 $uri->query_form([ foo => 1, foo => 2 ]);
613 $uri->query_form([ foo => [1, 2] ]);
614 $uri->query_form({ foo => [1, 2] });
616 The C<URI::QueryParam> module can be loaded to add further methods to
617 manipulate the form of a URI. See L<URI::QueryParam> for details.
619 =item $uri->query_keywords
621 =item $uri->query_keywords( $keywords, ... )
623 =item $uri->query_keywords( \@keywords )
625 Sets and returns query components that use the
626 keywords separated by "+" format.
628 The keywords can be set either by passing separate keywords directly
629 or by passing a reference to an array of keywords. Passing an empty
630 array removes the query component, whereas passing no arguments at
631 all leaves the component unchanged. The old value is always returned
632 as a list of separate words.
636 =head1 SERVER METHODS
638 For schemes where the I<authority> component denotes an Internet host,
639 the following methods are available in addition to the generic
646 =item $uri->userinfo( $new_userinfo )
648 Sets and returns the escaped userinfo part of the
651 For some schemes this is a user name and a password separated by
652 a colon. This practice is not recommended. Embedding passwords in
653 clear text (such as URI) has proven to be a security risk in almost
654 every case where it has been used.
658 =item $uri->host( $new_host )
660 Sets and returns the unescaped hostname.
662 If the $new_host string ends with a colon and a number, then this
663 number also sets the port.
667 =item $uri->port( $new_port )
669 Sets and returns the port. The port is a simple integer
670 that should be greater than 0.
672 If a port is not specified explicitly in the URI, then the URI scheme's default port
673 is returned. If you don't want the default port
674 substituted, then you can use the $uri->_port method instead.
676 =item $uri->host_port
678 =item $uri->host_port( $new_host_port )
680 Sets and returns the host and port as a single
681 unit. The returned value includes a port, even if it matches the
682 default port. The host part and the port part are separated by a
685 =item $uri->default_port
687 Returns the default port of the URI scheme to which $uri
688 belongs. For I<http> this is the number 80, for I<ftp> this
689 is the number 21, etc. The default port for a scheme can not be
694 =head1 SCHEME-SPECIFIC SUPPORT
696 Scheme-specific support is provided for the following URI schemes. For C<URI>
697 objects that do not belong to one of these, you can only use the common and
704 The I<data> URI scheme is specified in RFC 2397. It allows inclusion
705 of small data items as "immediate" data, as if it had been included
708 C<URI> objects belonging to the data scheme support the common methods
709 and two new methods to access their scheme-specific components:
710 $uri->media_type and $uri->data. See L<URI::data> for details.
714 An old specification of the I<file> URI scheme is found in RFC 1738.
715 A new RFC 2396 based specification in not available yet, but file URI
716 references are in common use.
718 C<URI> objects belonging to the file scheme support the common and
719 generic methods. In addition, they provide two methods for mapping file URIs
720 back to local file names; $uri->file and $uri->dir. See L<URI::file>
725 An old specification of the I<ftp> URI scheme is found in RFC 1738. A
726 new RFC 2396 based specification in not available yet, but ftp URI
727 references are in common use.
729 C<URI> objects belonging to the ftp scheme support the common,
730 generic and server methods. In addition, they provide two methods for
731 accessing the userinfo sub-components: $uri->user and $uri->password.
735 The I<gopher> URI scheme is specified in
736 <draft-murali-url-gopher-1996-12-04> and will hopefully be available
737 as a RFC 2396 based specification.
739 C<URI> objects belonging to the gopher scheme support the common,
740 generic and server methods. In addition, they support some methods for
741 accessing gopher-specific path components: $uri->gopher_type,
742 $uri->selector, $uri->search, $uri->string.
746 The I<http> URI scheme is specified in RFC 2616.
747 The scheme is used to reference resources hosted by HTTP servers.
749 C<URI> objects belonging to the http scheme support the common,
750 generic and server methods.
754 The I<https> URI scheme is a Netscape invention which is commonly
755 implemented. The scheme is used to reference HTTP servers through SSL
756 connections. Its syntax is the same as http, but the default
761 The I<ldap> URI scheme is specified in RFC 2255. LDAP is the
762 Lightweight Directory Access Protocol. An ldap URI describes an LDAP
763 search operation to perform to retrieve information from an LDAP
766 C<URI> objects belonging to the ldap scheme support the common,
767 generic and server methods as well as ldap-specific methods: $uri->dn,
768 $uri->attributes, $uri->scope, $uri->filter, $uri->extensions. See
769 L<URI::ldap> for details.
773 Like the I<ldap> URI scheme, but uses a UNIX domain socket. The
774 server methods are not supported, and the local socket path is
775 available as $uri->un_path. The I<ldapi> scheme is used by the
776 OpenLDAP package. There is no real specification for it, but it is
777 mentioned in various OpenLDAP manual pages.
781 Like the I<ldap> URI scheme, but uses an SSL connection. This
782 scheme is deprecated, as the preferred way is to use the I<start_tls>
787 The I<mailto> URI scheme is specified in RFC 2368. The scheme was
788 originally used to designate the Internet mailing address of an
789 individual or service. It has (in RFC 2368) been extended to allow
790 setting of other mail header fields and the message body.
792 C<URI> objects belonging to the mailto scheme support the common
793 methods and the generic query methods. In addition, they support the
794 following mailto-specific methods: $uri->to, $uri->headers.
798 The I<mms> URL specification can be found at L<http://sdp.ppona.com/>
799 C<URI> objects belonging to the mms scheme support the common,
800 generic, and server methods, with the exception of userinfo and
801 query-related sub-components.
805 The I<news>, I<nntp> and I<snews> URI schemes are specified in
806 <draft-gilman-news-url-01> and will hopefully be available as an RFC
807 2396 based specification soon.
809 C<URI> objects belonging to the news scheme support the common,
810 generic and server methods. In addition, they provide some methods to
811 access the path: $uri->group and $uri->message.
819 The I<pop> URI scheme is specified in RFC 2384. The scheme is used to
820 reference a POP3 mailbox.
822 C<URI> objects belonging to the pop scheme support the common, generic
823 and server methods. In addition, they provide two methods to access the
824 userinfo components: $uri->user and $uri->auth
828 An old specification of the I<rlogin> URI scheme is found in RFC
829 1738. C<URI> objects belonging to the rlogin scheme support the
830 common, generic and server methods.
834 The I<rtsp> URL specification can be found in section 3.2 of RFC 2326.
835 C<URI> objects belonging to the rtsp scheme support the common,
836 generic, and server methods, with the exception of userinfo and
837 query-related sub-components.
841 The I<rtspu> URI scheme is used to talk to RTSP servers over UDP
842 instead of TCP. The syntax is the same as rtsp.
846 Information about rsync is available from http://rsync.samba.org.
847 C<URI> objects belonging to the rsync scheme support the common,
848 generic and server methods. In addition, they provide methods to
849 access the userinfo sub-components: $uri->user and $uri->password.
853 The I<sip> URI specification is described in sections 19.1 and 25
854 of RFC 3261. C<URI> objects belonging to the sip scheme support the
855 common, generic, and server methods with the exception of path related
856 sub-components. In addition, they provide two methods to get and set
857 I<sip> parameters: $uri->params_form and $uri->params.
861 See I<sip> scheme. Its syntax is the same as sip, but the default
866 See I<news> scheme. Its syntax is the same as news, but the default
871 An old specification of the I<telnet> URI scheme is found in RFC
872 1738. C<URI> objects belonging to the telnet scheme support the
873 common, generic and server methods.
877 These URIs are used like I<telnet> URIs but for connections to IBM
878 mainframes. C<URI> objects belonging to the tn3270 scheme support the
879 common, generic and server methods.
883 Information about ssh is available at http://www.openssh.com/.
884 C<URI> objects belonging to the ssh scheme support the common,
885 generic and server methods. In addition, they provide methods to
886 access the userinfo sub-components: $uri->user and $uri->password.
890 The syntax of Uniform Resource Names is specified in RFC 2141. C<URI>
891 objects belonging to the urn scheme provide the common methods, and also the
892 methods $uri->nid and $uri->nss, which return the Namespace Identifier
893 and the Namespace-Specific String respectively.
895 The Namespace Identifier basically works like the Scheme identifier of
896 URIs, and further divides the URN namespace. Namespace Identifier
897 assignments are maintained at
898 <http://www.iana.org/assignments/urn-namespaces>.
900 Letter case is not significant for the Namespace Identifier. It is
901 always returned in lower case by the $uri->nid method. The $uri->_nid
902 method can be used if you want it in its original case.
904 =item B<urn>:B<isbn>:
906 The C<urn:isbn:> namespace contains International Standard Book
907 Numbers (ISBNs) and is described in RFC 3187. A C<URI> object belonging
908 to this namespace has the following extra methods (if the
909 Business::ISBN module is available): $uri->isbn,
910 $uri->isbn_publisher_code, $uri->isbn_country_code, $uri->isbn_as_ean.
914 The C<urn:oid:> namespace contains Object Identifiers (OIDs) and is
915 described in RFC 3061. An object identifier consists of sequences of digits
916 separated by dots. A C<URI> object belonging to this namespace has an
917 additional method called $uri->oid that can be used to get/set the oid
918 value. In a list context, oid numbers are returned as separate elements.
922 =head1 CONFIGURATION VARIABLES
924 The following configuration variables influence how the class and its
929 =item $URI::ABS_ALLOW_RELATIVE_SCHEME
931 Some older parsers used to allow the scheme name to be present in the
932 relative URL if it was the same as the base URL scheme. RFC 2396 says
933 that this should be avoided, but you can enable this old behaviour by
934 setting the $URI::ABS_ALLOW_RELATIVE_SCHEME variable to a TRUE value.
935 The difference is demonstrated by the following examples:
937 URI->new("http:foo")->abs("http://host/a/b")
940 local $URI::ABS_ALLOW_RELATIVE_SCHEME = 1;
941 URI->new("http:foo")->abs("http://host/a/b")
942 ==> "http:/host/a/foo"
945 =item $URI::ABS_REMOTE_LEADING_DOTS
947 You can also have the abs() method ignore excess ".."
948 segments in the relative URI by setting $URI::ABS_REMOTE_LEADING_DOTS
949 to a TRUE value. The difference is demonstrated by the following
952 URI->new("../../../foo")->abs("http://host/a/b")
953 ==> "http://host/../../foo"
955 local $URI::ABS_REMOTE_LEADING_DOTS = 1;
956 URI->new("../../../foo")->abs("http://host/a/b")
957 ==> "http://host/foo"
963 Using regexp variables like $1 directly as arguments to the URI methods
964 does not work too well with current perl implementations. I would argue
965 that this is actually a bug in perl. The workaround is to quote
971 =head1 PARSING URIs WITH REGEXP
973 As an alternative to this module, the following (official) regular
974 expression can be used to decode a URI:
976 my($scheme, $authority, $path, $query, $fragment) =
977 $uri =~ m|(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?|;
979 The C<URI::Split> module provides the function uri_split() as a
980 readable alternative.
984 L<URI::file>, L<URI::WithBase>, L<URI::QueryParam>, L<URI::Escape>,
985 L<URI::Split>, L<URI::Heuristic>
987 RFC 2396: "Uniform Resource Identifiers (URI): Generic Syntax",
988 Berners-Lee, Fielding, Masinter, August 1998.
990 http://www.iana.org/assignments/uri-schemes
992 http://www.iana.org/assignments/urn-namespaces
994 http://www.w3.org/Addressing/
998 Copyright 1995-2003 Gisle Aas.
1000 Copyright 1995 Martijn Koster.
1002 This program is free software; you can redistribute it and/or modify
1003 it under the same terms as Perl itself.
1005 =head1 AUTHORS / ACKNOWLEDGMENTS
1007 This module is based on the C<URI::URL> module, which in turn was
1008 (distantly) based on the C<wwwurl.pl> code in the libwww-perl for
1009 perl4 developed by Roy Fielding, as part of the Arcadia project at the
1010 University of California, Irvine, with contributions from Brooks
1013 C<URI::URL> was developed by Gisle Aas, Tim Bunce, Roy Fielding and
1014 Martijn Koster with input from other people on the libwww-perl mailing
1017 C<URI> and related subclasses was developed by Gisle Aas.