"Fossies" - the Fresh Open Source Software Archive

Member "install-tl-20200916/tlpkg/tlperl/site/lib/URI/Split.pm" (10 Mar 2019, 2353 Bytes) of package /windows/misc/install-tl.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 package URI::Split;
    2 
    3 use strict;
    4 use warnings;
    5 
    6 our $VERSION = '1.76';
    7 
    8 use Exporter 5.57 'import';
    9 our @EXPORT_OK = qw(uri_split uri_join);
   10 
   11 use URI::Escape ();
   12 
   13 sub uri_split {
   14      return $_[0] =~ m,(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?,;
   15 }
   16 
   17 sub uri_join {
   18     my($scheme, $auth, $path, $query, $frag) = @_;
   19     my $uri = defined($scheme) ? "$scheme:" : "";
   20     $path = "" unless defined $path;
   21     if (defined $auth) {
   22     $auth =~ s,([/?\#]), URI::Escape::escape_char($1),eg;
   23     $uri .= "//$auth";
   24     $path = "/$path" if length($path) && $path !~ m,^/,;
   25     }
   26     elsif ($path =~ m,^//,) {
   27     $uri .= "//";  # XXX force empty auth
   28     }
   29     unless (length $uri) {
   30     $path =~ s,(:), URI::Escape::escape_char($1),e while $path =~ m,^[^:/?\#]+:,;
   31     }
   32     $path =~ s,([?\#]), URI::Escape::escape_char($1),eg;
   33     $uri .= $path;
   34     if (defined $query) {
   35     $query =~ s,(\#), URI::Escape::escape_char($1),eg;
   36     $uri .= "?$query";
   37     }
   38     $uri .= "#$frag" if defined $frag;
   39     $uri;
   40 }
   41 
   42 1;
   43 
   44 __END__
   45 
   46 =head1 NAME
   47 
   48 URI::Split - Parse and compose URI strings
   49 
   50 =head1 SYNOPSIS
   51 
   52  use URI::Split qw(uri_split uri_join);
   53  ($scheme, $auth, $path, $query, $frag) = uri_split($uri);
   54  $uri = uri_join($scheme, $auth, $path, $query, $frag);
   55 
   56 =head1 DESCRIPTION
   57 
   58 Provides functions to parse and compose URI
   59 strings.  The following functions are provided:
   60 
   61 =over
   62 
   63 =item ($scheme, $auth, $path, $query, $frag) = uri_split($uri)
   64 
   65 Breaks up a URI string into its component
   66 parts.  An C<undef> value is returned for those parts that are not
   67 present.  The $path part is always present (but can be the empty
   68 string) and is thus never returned as C<undef>.
   69 
   70 No sensible value is returned if this function is called in a scalar
   71 context.
   72 
   73 =item $uri = uri_join($scheme, $auth, $path, $query, $frag)
   74 
   75 Puts together a URI string from its parts.
   76 Missing parts are signaled by passing C<undef> for the corresponding
   77 argument.
   78 
   79 Minimal escaping is applied to parts that contain reserved chars
   80 that would confuse a parser.  For instance, any occurrence of '?' or '#'
   81 in $path is always escaped, as it would otherwise be parsed back
   82 as a query or fragment.
   83 
   84 =back
   85 
   86 =head1 SEE ALSO
   87 
   88 L<URI>, L<URI::Escape>
   89 
   90 =head1 COPYRIGHT
   91 
   92 Copyright 2003, Gisle Aas
   93 
   94 This library is free software; you can redistribute it and/or
   95 modify it under the same terms as Perl itself.
   96 
   97 =cut