NAME
APR::URI - Perl API for URI manipulations
SSyynnooppssiissuse APR::URI ();
my $url = 'http://user:pass@example.com:80/foo?bar#item5';
# parse and break the url into components
my $parsed = APR::URI->parse($r->pool, $url);
print $parsed->scheme;
print $parsed->user;
print $parsed->password;
print $parsed->hostname;
print $parsed->port;
print $parsed->path;
print $parsed->rpath;
print $parsed->query;
print $parsed->fragment;
# reconstruct the url, after changing some components and completely
# removing other
$parsed->scheme($newscheme);
$parsed->user(undef);
$parsed->password(undef);
$parsed->hostname($newhostname);
$parsed->port($newport);
$parsed->path($newpath);
$parsed->query(undef);
$parsed->fragment(undef);
print $parsed->unparse;
# get the password field too (by default it's not revealed)
use APR::Const -compile => qw(URIUNPREVEALPASSWORD);
print $parsed->unparse(APR::Const::URIUNPREVEALPASSWORD);
# what the default port for the ftp protocol?
my $ftpport = APR::URI::portofscheme("ftp");
DDeessccrriippttiioonn"APR::URI" allows you to parse URI strings, manipulate each of the URI
elements and deparse them back into URIs.All "APR::URI" object accessors accept a string or an "undef" value as
an argument. Same goes for return value. It's important to distinguish between an empty string and "undef". For example let's say your code was:my $uri = 'http://example.com/foo?bar#item5';
my $parsed = APR::URI->parse($r->pool, $uri);
Now you no longer want to the query and fragment components in the final url. If you do:$parsed->fragment('');
$parsed->query('');
followed by:my $newuri = parsed->unparse;
the resulting URI will be:http://example.com/foo?#
which is probably not something that you've expected. In order to get rid of the separators, you must completely unset the fields you don't want to see. So, if you do:$parsed->fragment(undef);
$parsed->query(undef);
followed by:my $newuri = parsed->unparse;
the resulting URI will be: http://example.com/foo As mentioned earlier the same goes for return values, so continuing this example:my $newfragment = $parsed->fragment();
my $newquery = $parsed->query();
Both values now contain "undef", therefore you must be careful when using the return values, when you use them, as you may get warnings. Also make sure you read through "the unparse() section" as various optional flags affect how the deparsed URI is rendered. AAPPII"APR::URI" provides the following functions and/or methods:
""ffrraaggmmeenntt""Get/set trailing "#fragment" string
$oldval = $parsed->fragment($newval);
obj: $parsed ( "APR::URI object" )
opt arg1: $newval ( string or undef )
ret: $oldval ( string or undef )
since: 2.0.00 ""hhoossttiinnffoo"" Get/set combined "[user[:password]@]host[:port]"$oldval = $parsed->hostinfo($newval);
obj: $parsed ( "APR::URI object" )
opt arg1: $newval ( string or undef )
ret: $oldval ( string or undef )
since: 2.0.00 The "hostinfo" value is set automatically when "parse()" is called. It's not updated if any of the individual fields is modified. It's not used when "unparse()" is called. ""hhoossttnnaammee"" Get/set hostname$oldval = $parsed->hostname($newval);
obj: $parsed ( "APR::URI object" )
opt arg1: $newval ( string or undef )
ret: $oldval ( string or undef )
since: 2.0.00 ""ppaasssswwoorrdd"" Get/set password (as in http://user:password@host:port/)$oldval = $parsed->password($newval);
obj: $parsed ( "APR::URI object" )
opt arg1: $newval ( string or undef )
ret: $oldval ( string or undef )
since: 2.0.00 ""ppaarrssee"" Parse the URI string into URI components$parsed = APR::URI->parse($pool, $uri);
obj: $parsed ( "APR::URI object or class" )
arg1: $pool ( string ) ( "APR::Pool object" )
arg2: $uri ( string )
The URI to parseret: $parsed ( "APR::URI object or class" )
The parsed URI object since: 2.0.00 After parsing, if a component existed but was an empty string (e.g.empty query http://hostname/path?) - the corresponding accessor will
return an empty string. If a component didn't exist (e.g. no query parthttp://hostname/path) - the corresponding accessor will return
"undef". ""ppaatthh"" Get/set the request path$oldval = $parsed->path($newval);
obj: $parsed ( "APR::URI object" )
opt arg1: $newval ( string or undef )
ret: $oldval ( string or undef )
"/" if only "scheme://host" since: 2.0.00 ""rrppaatthh"" Gets the "path" minus the "pathinfo"$rpath = $parsed->rpath();
obj: $parsed ( "APR::URI object" )
opt arg1: $newval ( string or undef )
ret: $oldval ( string or undef )
The path minus the pathinfo since: 2.0.00 ""ppoorrtt"" Get/set port number$oldval = $parsed->port($newval);
obj: $parsed ( "APR::URI object" )
opt arg1: $newval ( number or string or undef )
ret: $oldval ( string or undef )
If the port component didn't appear in the parsed URI, APR internally calls "portofscheme()" to find out the port number for the given "scheme()". since: 2.0.00 ""ppoorrttooffsscchheemmee"" Return the default port for a given scheme. The recognized schemes are http, ftp, https, gopher, wais, nntp, snews and prospero.$port = APR::URI::portofscheme($scheme);
obj: $scheme ( string )
The scheme stringret: $port (integer)
The default port for this scheme since: 2.0.00 ""qquueerryy"" Get/set the query string (the part starting after '?' and all the waytill the end or the '#fragment' part if the latter exists).
$oldval = $parsed->query($newval);
obj: $parsed ( "APR::URI object" )
opt arg1: $newval ( string or undef )
ret: $oldval ( string or undef )
since: 2.0.00 ""sscchheemmee"" Get/set the protocol scheme ("http", "ftp", ...)$oldval = $parsed->scheme($newval);
obj: $parsed ( "APR::URI object" )
opt arg1: $newval ( string or undef )
ret: $oldval ( string or undef )
since: 2.0.00 ""uusseerr"" Get/set user name (as in http://user:password@host:port/)$oldval = $parsed->user($newval);
obj: $parsed ( "APR::URI object" )
opt arg1: $newval ( string or undef )
ret: $oldval ( string or undef )
since: 2.0.00 ""uunnppaarrssee"" Unparse the URI components back into a URI string$newuri = $parsed->unparse();
$newuri = $parsed->unparse($flags);
obj: $parsed ( "APR::URI object" )
opt arg1: $flags ( the APR::Const :uri constants )
By default the constant "APR::Const::URIUNPOMITPASSWORD" is passed. If you need to pass more than one flag use unary "|", e.g.:$flags = APR::Const::URIUNPOMITUSER|APR::Const::URIUNPOMITPASSWORD;
The valid "flags" constants are listed nextret: $newuri ( string )
since: 2.0.00 Valid "flags" constants: To import all URI constants you could do:use APR::Const -compile => qw(:uri);
but there is a significant amount of them, most irrelevant to this method. Therefore you probably don't want to do that. Instead specify explicitly the ones that you need. All the relevant to this methodconstants start with "APR::URIUNP".
And the available constants are: "APR::Const::URIUNPOMITSITEPART" Don't show "scheme", "user", "password", "hostname" and "port" components (i.e. if you want only the relative URI) "APR::Const::URIUNPOMITUSER" Hide the "user" component "APR::Const::URIUNPOMITPASSWORD" Hide the "password" component (the default) "APR::Const::URIUNPREVEALPASSWORD" Reveal the "password" component "APR::Const::URIUNPOMITPATHINFO" Don't show "path", "query" and "fragment" components "APR::Const::URIUNPOMITQUERY" Don't show "query" and "fragment" components Notice that some flags overlap.If the optional $flags argument is passed and contains no
"APR::Const::URIUNPOMITPASSWORD" and no"APR::Const::URIUNPREVEALPASSWORD" - the "password" part will be
rendered as a literal "XXXXXXXX" string. If the "port" number matches the "portofscheme()", the unparsed URI won't include it and there is no flag to force that "port" to appear.If the "port" number is non-standard it will show up in the unparsed
string. Examples: Starting with the parsed URL:use APR::URI ();
my $url = 'http://user:pass@example.com:80/foo?bar#item5';
my $parsed = APR::URI->parse($r->pool, $url);
deparse it back including and excluding parts, using different values for the optional "flags" argument: +o Show all but the "password" fields:print $parsed->unparse;
Prints:http://user@example.com/foo?bar#item5
Notice that the "port" field is gone too, since it was a default "port" for "scheme" "http://". +o Include the "password" field (by default it's not revealed)use APR::Const -compile => qw(URIUNPREVEALPASSWORD);
print $parsed->unparse(APR::Const::URIUNPREVEALPASSWORD);
Prints:http://user:pass@example.com/foo?bar#item5
+o Show all fields but the last three, "path", "query" and "fragment":use APR::Const -compile => qw(URIUNPREVEALPASSWORD
APR::Const::URIUNPOMITPATHINFO);print $parsed->unparse(
APR::Const::URIUNPREVEALPASSWORD|URIUNPOMITPATHINFO); Prints: http://user:pass@example.com SSeeee AAllssoo "Apache2::URI", modperl 2.0 documentation. CCooppyyrriigghhtt modperl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0. AAuutthhoorrss The modperl development team and numerous contributors.perl v5.8.8 apachemodperl-1012.010~52-:1:0m-o2d0perl-2.0.2::docs::api::APR::URI(3)