5 use vars qw(@ISA @EXPORT_OK);
8 @EXPORT_OK = qw(uri_split uri_join);
13 return $_[0] =~ m,(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?,;
17 my($scheme, $auth, $path, $query, $frag) = @_;
18 my $uri = defined($scheme) ? "$scheme:" : "";
19 $path = "" unless defined $path;
21 $auth =~ s,([/?\#]),$URI::Escape::escapes{$1},g;
23 $path = "/$path" if length($path) && $path !~ m,^/,;
25 elsif ($path =~ m,^//,) {
26 $uri .= "//"; # XXX force empty auth
28 unless (length $uri) {
29 $path =~ s,(:),$URI::Escape::escapes{$1}, while $path =~ m,^[^:/?\#]+:,;
31 $path =~ s,([?\#]),$URI::Escape::escapes{$1},g;
34 $query =~ s,(\#),$URI::Escape::escapes{$1},g;
37 $uri .= "#$frag" if defined $frag;
47 URI::Split - Parse and compose URI strings
51 use URI::Split qw(uri_split uri_join);
52 ($scheme, $auth, $path, $query, $frag) = uri_split($uri);
53 $uri = uri_join($scheme, $auth, $path, $query, $frag);
57 Provides functions to parse and compose URI
58 strings. The following functions are provided:
62 =item ($scheme, $auth, $path, $query, $frag) = uri_split($uri)
64 Breaks up a URI string into its component
65 parts. An C<undef> value is returned for those parts that are not
66 present. The $path part is always present (but can be the empty
67 string) and is thus never returned as C<undef>.
69 No sensible value is returned if this function is called in a scalar
72 =item $uri = uri_join($scheme, $auth, $path, $query, $frag)
74 Puts together a URI string from its parts.
75 Missing parts are signaled by passing C<undef> for the corresponding
78 Minimal escaping is applied to parts that contain reserved chars
79 that would confuse a parser. For instance, any occurrence of '?' or '#'
80 in $path is always escaped, as it would otherwise be parsed back
81 as a query or fragment.
87 L<URI>, L<URI::Escape>
91 Copyright 2003, Gisle Aas
93 This library is free software; you can redistribute it and/or
94 modify it under the same terms as Perl itself.