1URI(3) User Contributed Perl Documentation URI(3)
2
3
4
6 URI - Uniform Resource Identifiers (absolute and relative)
7
9 use URI ();
10
11 $u1 = URI->new("http://www.example.com");
12 $u2 = URI->new("foo", "http");
13 $u3 = $u2->abs($u1);
14 $u4 = $u3->clone;
15 $u5 = URI->new("HTTP://WWW.example.com:80")->canonical;
16
17 $str = $u->as_string;
18 $str = "$u";
19
20 $scheme = $u->scheme;
21 $opaque = $u->opaque;
22 $path = $u->path;
23 $frag = $u->fragment;
24
25 $u->scheme("ftp");
26 $u->host("ftp.example.com");
27 $u->path("cpan/");
28
30 This module implements the "URI" class. Objects of this class
31 represent "Uniform Resource Identifier references" as specified in RFC
32 2396 (and updated by RFC 2732).
33
34 A Uniform Resource Identifier is a compact string of characters that
35 identifies an abstract or physical resource. A Uniform Resource
36 Identifier can be further classified as either a Uniform Resource
37 Locator (URL) or a Uniform Resource Name (URN). The distinction
38 between URL and URN does not matter to the "URI" class interface. A
39 "URI-reference" is a URI that may have additional information attached
40 in the form of a fragment identifier.
41
42 An absolute URI reference consists of three parts: a scheme, a scheme-
43 specific part and a fragment identifier. A subset of URI references
44 share a common syntax for hierarchical namespaces. For these, the
45 scheme-specific part is further broken down into authority, path and
46 query components. These URIs can also take the form of relative URI
47 references, where the scheme (and usually also the authority) component
48 is missing, but implied by the context of the URI reference. The three
49 forms of URI reference syntax are summarized as follows:
50
51 <scheme>:<scheme-specific-part>#<fragment>
52 <scheme>://<authority><path>?<query>#<fragment>
53 <path>?<query>#<fragment>
54
55 The components into which a URI reference can be divided depend on the
56 scheme. The "URI" class provides methods to get and set the individual
57 components. The methods available for a specific "URI" object depend
58 on the scheme.
59
61 The following methods construct new "URI" objects:
62
63 $uri = URI->new( $str )
64 $uri = URI->new( $str, $scheme )
65 Constructs a new URI object. The string representation of a URI is
66 given as argument, together with an optional scheme specification.
67 Common URI wrappers like "" and <>, as well as leading and trailing
68 white space, are automatically removed from the $str argument
69 before it is processed further.
70
71 The constructor determines the scheme, maps this to an appropriate
72 URI subclass, constructs a new object of that class and returns it.
73
74 If the scheme isn't one of those that URI recognizes, you still get
75 an URI object back that you can access the generic methods on. The
76 "$uri->has_recognized_scheme" method can be used to test for this.
77
78 The $scheme argument is only used when $str is a relative URI. It
79 can be either a simple string that denotes the scheme, a string
80 containing an absolute URI reference, or an absolute "URI" object.
81 If no $scheme is specified for a relative URI $str, then $str is
82 simply treated as a generic URI (no scheme-specific methods
83 available).
84
85 The set of characters available for building URI references is
86 restricted (see URI::Escape). Characters outside this set are
87 automatically escaped by the URI constructor.
88
89 $uri = URI->new_abs( $str, $base_uri )
90 Constructs a new absolute URI object. The $str argument can denote
91 a relative or absolute URI. If relative, then it is absolutized
92 using $base_uri as base. The $base_uri must be an absolute URI.
93
94 $uri = URI::file->new( $filename )
95 $uri = URI::file->new( $filename, $os )
96 Constructs a new file URI from a file name. See URI::file.
97
98 $uri = URI::file->new_abs( $filename )
99 $uri = URI::file->new_abs( $filename, $os )
100 Constructs a new absolute file URI from a file name. See
101 URI::file.
102
103 $uri = URI::file->cwd
104 Returns the current working directory as a file URI. See
105 URI::file.
106
107 $uri->clone
108 Returns a copy of the $uri.
109
111 The methods described in this section are available for all "URI"
112 objects.
113
114 Methods that give access to components of a URI always return the old
115 value of the component. The value returned is "undef" if the component
116 was not present. There is generally a difference between a component
117 that is empty (represented as "") and a component that is missing
118 (represented as "undef"). If an accessor method is given an argument,
119 it updates the corresponding component in addition to returning the old
120 value of the component. Passing an undefined argument removes the
121 component (if possible). The description of each accessor method
122 indicates whether the component is passed as an escaped (percent-
123 encoded) or an unescaped string. A component that can be further
124 divided into sub-parts are usually passed escaped, as unescaping might
125 change its semantics.
126
127 The common methods available for all URI are:
128
129 $uri->scheme
130 $uri->scheme( $new_scheme )
131 Sets and returns the scheme part of the $uri. If the $uri is
132 relative, then $uri->scheme returns "undef". If called with an
133 argument, it updates the scheme of $uri, possibly changing the
134 class of $uri, and returns the old scheme value. The method croaks
135 if the new scheme name is illegal; a scheme name must begin with a
136 letter and must consist of only US-ASCII letters, numbers, and a
137 few special marks: ".", "+", "-". This restriction effectively
138 means that the scheme must be passed unescaped. Passing an
139 undefined argument to the scheme method makes the URI relative (if
140 possible).
141
142 Letter case does not matter for scheme names. The string returned
143 by $uri->scheme is always lowercase. If you want the scheme just
144 as it was written in the URI in its original case, you can use the
145 $uri->_scheme method instead.
146
147 $uri->has_recognized_scheme
148 Returns TRUE if the URI scheme is one that URI recognizes.
149
150 It will also be TRUE for relative URLs where a recognized scheme
151 was provided to the constructor, even if "$uri->scheme" returns
152 "undef" for these.
153
154 $uri->opaque
155 $uri->opaque( $new_opaque )
156 Sets and returns the scheme-specific part of the $uri (everything
157 between the scheme and the fragment) as an escaped string.
158
159 $uri->path
160 $uri->path( $new_path )
161 Sets and returns the same value as $uri->opaque unless the URI
162 supports the generic syntax for hierarchical namespaces. In that
163 case the generic method is overridden to set and return the part of
164 the URI between the host name and the fragment.
165
166 $uri->fragment
167 $uri->fragment( $new_frag )
168 Returns the fragment identifier of a URI reference as an escaped
169 string.
170
171 $uri->as_string
172 Returns a URI object to a plain ASCII string. URI objects are also
173 converted to plain strings automatically by overloading. This
174 means that $uri objects can be used as plain strings in most Perl
175 constructs.
176
177 $uri->as_iri
178 Returns a Unicode string representing the URI. Escaped UTF-8
179 sequences representing non-ASCII characters are turned into their
180 corresponding Unicode code point.
181
182 $uri->canonical
183 Returns a normalized version of the URI. The rules for
184 normalization are scheme-dependent. They usually involve
185 lowercasing the scheme and Internet host name components, removing
186 the explicit port specification if it matches the default port,
187 uppercasing all escape sequences, and unescaping octets that can be
188 better represented as plain characters.
189
190 For efficiency reasons, if the $uri is already in normalized form,
191 then a reference to it is returned instead of a copy.
192
193 $uri->eq( $other_uri )
194 URI::eq( $first_uri, $other_uri )
195 Tests whether two URI references are equal. URI references that
196 normalize to the same string are considered equal. The method can
197 also be used as a plain function which can also test two string
198 arguments.
199
200 If you need to test whether two "URI" object references denote the
201 same object, use the '==' operator.
202
203 $uri->abs( $base_uri )
204 Returns an absolute URI reference. If $uri is already absolute,
205 then a reference to it is simply returned. If the $uri is
206 relative, then a new absolute URI is constructed by combining the
207 $uri and the $base_uri, and returned.
208
209 $uri->rel( $base_uri )
210 Returns a relative URI reference if it is possible to make one that
211 denotes the same resource relative to $base_uri. If not, then $uri
212 is simply returned.
213
214 $uri->secure
215 Returns a TRUE value if the URI is considered to point to a
216 resource on a secure channel, such as an SSL or TLS encrypted one.
217
219 The following methods are available to schemes that use the
220 common/generic syntax for hierarchical namespaces. The descriptions of
221 schemes below indicate which these are. Unrecognized schemes are
222 assumed to support the generic syntax, and therefore the following
223 methods:
224
225 $uri->authority
226 $uri->authority( $new_authority )
227 Sets and returns the escaped authority component of the $uri.
228
229 $uri->path
230 $uri->path( $new_path )
231 Sets and returns the escaped path component of the $uri (the part
232 between the host name and the query or fragment). The path can
233 never be undefined, but it can be the empty string.
234
235 $uri->path_query
236 $uri->path_query( $new_path_query )
237 Sets and returns the escaped path and query components as a single
238 entity. The path and the query are separated by a "?" character,
239 but the query can itself contain "?".
240
241 $uri->path_segments
242 $uri->path_segments( $segment, ... )
243 Sets and returns the path. In a scalar context, it returns the
244 same value as $uri->path. In a list context, it returns the
245 unescaped path segments that make up the path. Path segments that
246 have parameters are returned as an anonymous array. The first
247 element is the unescaped path segment proper; subsequent elements
248 are escaped parameter strings. Such an anonymous array uses
249 overloading so it can be treated as a string too, but this string
250 does not include the parameters.
251
252 Note that absolute paths have the empty string as their first
253 path_segment, i.e. the path "/foo/bar" have 3 path_segments; "",
254 "foo" and "bar".
255
256 $uri->query
257 $uri->query( $new_query )
258 Sets and returns the escaped query component of the $uri.
259
260 $uri->query_form
261 $uri->query_form( $key1 => $val1, $key2 => $val2, ... )
262 $uri->query_form( $key1 => $val1, $key2 => $val2, ..., $delim )
263 $uri->query_form( \@key_value_pairs )
264 $uri->query_form( \@key_value_pairs, $delim )
265 $uri->query_form( \%hash )
266 $uri->query_form( \%hash, $delim )
267 Sets and returns query components that use the
268 application/x-www-form-urlencoded format. Key/value pairs are
269 separated by "&", and the key is separated from the value by a "="
270 character.
271
272 The form can be set either by passing separate key/value pairs, or
273 via an array or hash reference. Passing an empty array or an empty
274 hash removes the query component, whereas passing no arguments at
275 all leaves the component unchanged. The order of keys is undefined
276 if a hash reference is passed. The old value is always returned as
277 a list of separate key/value pairs. Assigning this list to a hash
278 is unwise as the keys returned might repeat.
279
280 The values passed when setting the form can be plain strings or
281 references to arrays of strings. Passing an array of values has
282 the same effect as passing the key repeatedly with one value at a
283 time. All the following statements have the same effect:
284
285 $uri->query_form(foo => 1, foo => 2);
286 $uri->query_form(foo => [1, 2]);
287 $uri->query_form([ foo => 1, foo => 2 ]);
288 $uri->query_form([ foo => [1, 2] ]);
289 $uri->query_form({ foo => [1, 2] });
290
291 The $delim parameter can be passed as ";" to force the key/value
292 pairs to be delimited by ";" instead of "&" in the query string.
293 This practice is often recommended for URLs embedded in HTML or XML
294 documents as this avoids the trouble of escaping the "&" character.
295 You might also set the $URI::DEFAULT_QUERY_FORM_DELIMITER variable
296 to ";" for the same global effect.
297
298 @keys = $u->query_param
299 @values = $u->query_param( $key )
300 $first_value = $u->query_param( $key )
301 $u->query_param( $key, $value,... )
302 If $u->query_param is called with no arguments, it returns all the
303 distinct parameter keys of the URI. In a scalar context it returns
304 the number of distinct keys.
305
306 When a $key argument is given, the method returns the parameter
307 values with the given key. In a scalar context, only the first
308 parameter value is returned.
309
310 If additional arguments are given, they are used to update
311 successive parameters with the given key. If any of the values
312 provided are array references, then the array is dereferenced to
313 get the actual values.
314
315 Please note that you can supply multiple values to this method, but
316 you cannot supply multiple keys.
317
318 Do this:
319
320 $uri->query_param( widget_id => 1, 5, 9 );
321
322 Do NOT do this:
323
324 $uri->query_param( widget_id => 1, frobnicator_id => 99 );
325
326 $u->query_param_append($key, $value,...)
327 Adds new parameters with the given key without touching any old
328 parameters with the same key. It can be explained as a more
329 efficient version of:
330
331 $u->query_param($key,
332 $u->query_param($key),
333 $value,...);
334
335 One difference is that this expression would return the old values
336 of $key, whereas the query_param_append() method does not.
337
338 @values = $u->query_param_delete($key)
339 $first_value = $u->query_param_delete($key)
340 Deletes all key/value pairs with the given key. The old values are
341 returned. In a scalar context, only the first value is returned.
342
343 Using the query_param_delete() method is slightly more efficient
344 than the equivalent:
345
346 $u->query_param($key, []);
347
348 $hashref = $u->query_form_hash
349 $u->query_form_hash( \%new_form )
350 Returns a reference to a hash that represents the query form's
351 key/value pairs. If a key occurs multiple times, then the hash
352 value becomes an array reference.
353
354 Note that sequence information is lost. This means that:
355
356 $u->query_form_hash($u->query_form_hash);
357
358 is not necessarily a no-op, as it may reorder the key/value pairs.
359 The values returned by the query_param() method should stay the
360 same though.
361
362 $uri->query_keywords
363 $uri->query_keywords( $keywords, ... )
364 $uri->query_keywords( \@keywords )
365 Sets and returns query components that use the keywords separated
366 by "+" format.
367
368 The keywords can be set either by passing separate keywords
369 directly or by passing a reference to an array of keywords.
370 Passing an empty array removes the query component, whereas passing
371 no arguments at all leaves the component unchanged. The old value
372 is always returned as a list of separate words.
373
375 For schemes where the authority component denotes an Internet host, the
376 following methods are available in addition to the generic methods.
377
378 $uri->userinfo
379 $uri->userinfo( $new_userinfo )
380 Sets and returns the escaped userinfo part of the authority
381 component.
382
383 For some schemes this is a user name and a password separated by a
384 colon. This practice is not recommended. Embedding passwords in
385 clear text (such as URI) has proven to be a security risk in almost
386 every case where it has been used.
387
388 $uri->host
389 $uri->host( $new_host )
390 Sets and returns the unescaped hostname.
391
392 If the $new_host string ends with a colon and a number, then this
393 number also sets the port.
394
395 For IPv6 addresses the brackets around the raw address is removed
396 in the return value from $uri->host. When setting the host
397 attribute to an IPv6 address you can use a raw address or one
398 enclosed in brackets. The address needs to be enclosed in brackets
399 if you want to pass in a new port value as well.
400
401 my $uri = URI->new("http://www.\xC3\xBCri-sample/foo/bar.html");
402 print $u->host; # www.xn--ri-sample-fra0f
403
404 $uri->ihost
405 Returns the host in Unicode form. Any IDNA A-labels (encoded
406 unicode chars with xn-- prefix) are turned into U-labels (unicode
407 chars).
408
409 my $uri = URI->new("http://www.\xC3\xBCri-sample/foo/bar.html");
410 print $u->ihost; # www.\xC3\xBCri-sample
411
412 $uri->port
413 $uri->port( $new_port )
414 Sets and returns the port. The port is a simple integer that
415 should be greater than 0.
416
417 If a port is not specified explicitly in the URI, then the URI
418 scheme's default port is returned. If you don't want the default
419 port substituted, then you can use the $uri->_port method instead.
420
421 $uri->host_port
422 $uri->host_port( $new_host_port )
423 Sets and returns the host and port as a single unit. The returned
424 value includes a port, even if it matches the default port. The
425 host part and the port part are separated by a colon: ":".
426
427 For IPv6 addresses the bracketing is preserved; thus
428 URI->new("http://[::1]/")->host_port returns "[::1]:80". Contrast
429 this with $uri->host which will remove the brackets.
430
431 $uri->default_port
432 Returns the default port of the URI scheme to which $uri belongs.
433 For http this is the number 80, for ftp this is the number 21, etc.
434 The default port for a scheme can not be changed.
435
437 Scheme-specific support is provided for the following URI schemes. For
438 "URI" objects that do not belong to one of these, you can only use the
439 common and generic methods.
440
441 data:
442 The data URI scheme is specified in RFC 2397. It allows inclusion
443 of small data items as "immediate" data, as if it had been included
444 externally.
445
446 "URI" objects belonging to the data scheme support the common
447 methods and two new methods to access their scheme-specific
448 components: $uri->media_type and $uri->data. See URI::data for
449 details.
450
451 file:
452 An old specification of the file URI scheme is found in RFC 1738.
453 A new RFC 2396 based specification in not available yet, but file
454 URI references are in common use.
455
456 "URI" objects belonging to the file scheme support the common and
457 generic methods. In addition, they provide two methods for mapping
458 file URIs back to local file names; $uri->file and $uri->dir. See
459 URI::file for details.
460
461 ftp:
462 An old specification of the ftp URI scheme is found in RFC 1738. A
463 new RFC 2396 based specification in not available yet, but ftp URI
464 references are in common use.
465
466 "URI" objects belonging to the ftp scheme support the common,
467 generic and server methods. In addition, they provide two methods
468 for accessing the userinfo sub-components: $uri->user and
469 $uri->password.
470
471 gopher:
472 The gopher URI scheme is specified in
473 <draft-murali-url-gopher-1996-12-04> and will hopefully be
474 available as a RFC 2396 based specification.
475
476 "URI" objects belonging to the gopher scheme support the common,
477 generic and server methods. In addition, they support some methods
478 for accessing gopher-specific path components: $uri->gopher_type,
479 $uri->selector, $uri->search, $uri->string.
480
481 http:
482 The http URI scheme is specified in RFC 2616. The scheme is used
483 to reference resources hosted by HTTP servers.
484
485 "URI" objects belonging to the http scheme support the common,
486 generic and server methods.
487
488 https:
489 The https URI scheme is a Netscape invention which is commonly
490 implemented. The scheme is used to reference HTTP servers through
491 SSL connections. Its syntax is the same as http, but the default
492 port is different.
493
494 icap:
495 The icap URI scheme is specified in RFC 3507
496 <http://tools.ietf.org/html/rfc3507>. The scheme is used to
497 reference resources hosted by ICAP servers.
498
499 "URI" objects belonging to the icap scheme support the common,
500 generic and server methods.
501
502 icaps:
503 The icaps URI scheme is specified in RFC 3507
504 <http://tools.ietf.org/html/rfc3507> as well. The scheme is used
505 to reference ICAP servers through SSL connections. Its syntax is
506 the same as icap, including the same default port.
507
508 ldap:
509 The ldap URI scheme is specified in RFC 2255. LDAP is the
510 Lightweight Directory Access Protocol. An ldap URI describes an
511 LDAP search operation to perform to retrieve information from an
512 LDAP directory.
513
514 "URI" objects belonging to the ldap scheme support the common,
515 generic and server methods as well as ldap-specific methods:
516 $uri->dn, $uri->attributes, $uri->scope, $uri->filter,
517 $uri->extensions. See URI::ldap for details.
518
519 ldapi:
520 Like the ldap URI scheme, but uses a UNIX domain socket. The
521 server methods are not supported, and the local socket path is
522 available as $uri->un_path. The ldapi scheme is used by the
523 OpenLDAP package. There is no real specification for it, but it is
524 mentioned in various OpenLDAP manual pages.
525
526 ldaps:
527 Like the ldap URI scheme, but uses an SSL connection. This scheme
528 is deprecated, as the preferred way is to use the start_tls
529 mechanism.
530
531 mailto:
532 The mailto URI scheme is specified in RFC 2368. The scheme was
533 originally used to designate the Internet mailing address of an
534 individual or service. It has (in RFC 2368) been extended to allow
535 setting of other mail header fields and the message body.
536
537 "URI" objects belonging to the mailto scheme support the common
538 methods and the generic query methods. In addition, they support
539 the following mailto-specific methods: $uri->to, $uri->headers.
540
541 Note that the "foo@example.com" part of a mailto is not the
542 "userinfo" and "host" but instead the "path". This allows a mailto
543 URI to contain multiple comma separated email addresses.
544
545 mms:
546 The mms URL specification can be found at <http://sdp.ppona.com/>.
547 "URI" objects belonging to the mms scheme support the common,
548 generic, and server methods, with the exception of userinfo and
549 query-related sub-components.
550
551 news:
552 The news, nntp and snews URI schemes are specified in
553 <draft-gilman-news-url-01> and will hopefully be available as an
554 RFC 2396 based specification soon. (Update: as of April 2010, they
555 are in RFC 5538 <https://tools.ietf.org/html/rfc5538>.
556
557 "URI" objects belonging to the news scheme support the common,
558 generic and server methods. In addition, they provide some methods
559 to access the path: $uri->group and $uri->message.
560
561 nntp:
562 See news scheme.
563
564 nntps:
565 See news scheme and RFC 5538 <https://tools.ietf.org/html/rfc5538>.
566
567 pop:
568 The pop URI scheme is specified in RFC 2384. The scheme is used to
569 reference a POP3 mailbox.
570
571 "URI" objects belonging to the pop scheme support the common,
572 generic and server methods. In addition, they provide two methods
573 to access the userinfo components: $uri->user and $uri->auth
574
575 rlogin:
576 An old specification of the rlogin URI scheme is found in RFC 1738.
577 "URI" objects belonging to the rlogin scheme support the common,
578 generic and server methods.
579
580 rtsp:
581 The rtsp URL specification can be found in section 3.2 of RFC 2326.
582 "URI" objects belonging to the rtsp scheme support the common,
583 generic, and server methods, with the exception of userinfo and
584 query-related sub-components.
585
586 rtspu:
587 The rtspu URI scheme is used to talk to RTSP servers over UDP
588 instead of TCP. The syntax is the same as rtsp.
589
590 rsync:
591 Information about rsync is available from
592 <http://rsync.samba.org/>. "URI" objects belonging to the rsync
593 scheme support the common, generic and server methods. In
594 addition, they provide methods to access the userinfo sub-
595 components: $uri->user and $uri->password.
596
597 sip:
598 The sip URI specification is described in sections 19.1 and 25 of
599 RFC 3261. "URI" objects belonging to the sip scheme support the
600 common, generic, and server methods with the exception of path
601 related sub-components. In addition, they provide two methods to
602 get and set sip parameters: $uri->params_form and $uri->params.
603
604 sips:
605 See sip scheme. Its syntax is the same as sip, but the default
606 port is different.
607
608 snews:
609 See news scheme. Its syntax is the same as news, but the default
610 port is different.
611
612 telnet:
613 An old specification of the telnet URI scheme is found in RFC 1738.
614 "URI" objects belonging to the telnet scheme support the common,
615 generic and server methods.
616
617 tn3270:
618 These URIs are used like telnet URIs but for connections to IBM
619 mainframes. "URI" objects belonging to the tn3270 scheme support
620 the common, generic and server methods.
621
622 ssh:
623 Information about ssh is available at <http://www.openssh.com/>.
624 "URI" objects belonging to the ssh scheme support the common,
625 generic and server methods. In addition, they provide methods to
626 access the userinfo sub-components: $uri->user and $uri->password.
627
628 sftp:
629 "URI" objects belonging to the sftp scheme support the common,
630 generic and server methods. In addition, they provide methods to
631 access the userinfo sub-components: $uri->user and $uri->password.
632
633 urn:
634 The syntax of Uniform Resource Names is specified in RFC 2141.
635 "URI" objects belonging to the urn scheme provide the common
636 methods, and also the methods $uri->nid and $uri->nss, which return
637 the Namespace Identifier and the Namespace-Specific String
638 respectively.
639
640 The Namespace Identifier basically works like the Scheme identifier
641 of URIs, and further divides the URN namespace. Namespace
642 Identifier assignments are maintained at
643 <http://www.iana.org/assignments/urn-namespaces>.
644
645 Letter case is not significant for the Namespace Identifier. It is
646 always returned in lower case by the $uri->nid method. The
647 $uri->_nid method can be used if you want it in its original case.
648
649 urn:isbn:
650 The "urn:isbn:" namespace contains International Standard Book
651 Numbers (ISBNs) and is described in RFC 3187. A "URI" object
652 belonging to this namespace has the following extra methods (if the
653 Business::ISBN module is available): $uri->isbn,
654 $uri->isbn_publisher_code, $uri->isbn_group_code (formerly
655 isbn_country_code, which is still supported by issues a deprecation
656 warning), $uri->isbn_as_ean.
657
658 urn:oid:
659 The "urn:oid:" namespace contains Object Identifiers (OIDs) and is
660 described in RFC 3061. An object identifier consists of sequences
661 of digits separated by dots. A "URI" object belonging to this
662 namespace has an additional method called $uri->oid that can be
663 used to get/set the oid value. In a list context, oid numbers are
664 returned as separate elements.
665
667 The following configuration variables influence how the class and its
668 methods behave:
669
670 $URI::ABS_ALLOW_RELATIVE_SCHEME
671 Some older parsers used to allow the scheme name to be present in
672 the relative URL if it was the same as the base URL scheme. RFC
673 2396 says that this should be avoided, but you can enable this old
674 behaviour by setting the $URI::ABS_ALLOW_RELATIVE_SCHEME variable
675 to a TRUE value. The difference is demonstrated by the following
676 examples:
677
678 URI->new("http:foo")->abs("http://host/a/b")
679 ==> "http:foo"
680
681 local $URI::ABS_ALLOW_RELATIVE_SCHEME = 1;
682 URI->new("http:foo")->abs("http://host/a/b")
683 ==> "http:/host/a/foo"
684
685 $URI::ABS_REMOTE_LEADING_DOTS
686 You can also have the abs() method ignore excess ".." segments in
687 the relative URI by setting $URI::ABS_REMOTE_LEADING_DOTS to a TRUE
688 value. The difference is demonstrated by the following examples:
689
690 URI->new("../../../foo")->abs("http://host/a/b")
691 ==> "http://host/../../foo"
692
693 local $URI::ABS_REMOTE_LEADING_DOTS = 1;
694 URI->new("../../../foo")->abs("http://host/a/b")
695 ==> "http://host/foo"
696
697 $URI::DEFAULT_QUERY_FORM_DELIMITER
698 This value can be set to ";" to have the query form "key=value"
699 pairs delimited by ";" instead of "&" which is the default.
700
702 URI_HAS_RESERVED_SQUARE_BRACKETS
703 Before version 5.11, URI treated square brackets as reserved
704 characters throughout the whole URI string. However, these brackets
705 are reserved only within the authority/host part of the URI and
706 nowhere else (RFC 3986).
707
708 Starting with version 5.11, URI takes this distinction into
709 account. Setting the environment variable
710 "URI_HAS_RESERVED_SQUARE_BRACKETS" (programmatically or via the
711 shell), restores the old behavior.
712
713 #-- restore 5.10 behavior programmatically
714 BEGIN {
715 $ENV{URI_HAS_RESERVED_SQUARE_BRACKETS} = 1;
716 }
717 use URI ();
718
719 Note: This environment variable is just used during initialization
720 and has to be set
721 before module URI is used/required. Changing it at run time
722 has no effect.
723
724 Its value can be checked programmatically by accessing the constant
725 "URI::HAS_RESERVED_SQUARE_BRACKETS".
726
728 There are some things that are not quite right:
729
730 • Using regexp variables like $1 directly as arguments to the URI
731 accessor methods does not work too well with current perl
732 implementations. I would argue that this is actually a bug in
733 perl. The workaround is to quote them. Example:
734
735 /(...)/ || die;
736 $u->query("$1");
737
738 • The escaping (percent encoding) of chars in the 128 .. 255 range
739 passed to the URI constructor or when setting URI parts using the
740 accessor methods depend on the state of the internal UTF8 flag (see
741 utf8::is_utf8) of the string passed. If the UTF8 flag is set the
742 UTF-8 encoded version of the character is percent encoded. If the
743 UTF8 flag isn't set the Latin-1 version (byte) of the character is
744 percent encoded. This basically exposes the internal encoding of
745 Perl strings.
746
748 As an alternative to this module, the following (official) regular
749 expression can be used to decode a URI:
750
751 my($scheme, $authority, $path, $query, $fragment) =
752 $uri =~ m|(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?|;
753
754 The "URI::Split" module provides the function uri_split() as a readable
755 alternative.
756
758 URI::file, URI::WithBase, URI::Escape, URI::Split, URI::Heuristic
759
760 RFC 2396: "Uniform Resource Identifiers (URI): Generic Syntax",
761 Berners-Lee, Fielding, Masinter, August 1998.
762
763 <http://www.iana.org/assignments/uri-schemes>
764
765 <http://www.iana.org/assignments/urn-namespaces>
766
767 <http://www.w3.org/Addressing/>
768
770 Copyright 1995-2009 Gisle Aas.
771
772 Copyright 1995 Martijn Koster.
773
774 This program is free software; you can redistribute it and/or modify it
775 under the same terms as Perl itself.
776
778 This module is based on the "URI::URL" module, which in turn was
779 (distantly) based on the "wwwurl.pl" code in the libwww-perl for perl4
780 developed by Roy Fielding, as part of the Arcadia project at the
781 University of California, Irvine, with contributions from Brooks
782 Cutter.
783
784 "URI::URL" was developed by Gisle Aas, Tim Bunce, Roy Fielding and
785 Martijn Koster with input from other people on the libwww-perl mailing
786 list.
787
788 "URI" and related subclasses was developed by Gisle Aas.
789
790
791
792perl v5.38.0 2023-08-24 URI(3)