libapa...R::URI(3pm)
π NAME π
APR::URI β Perl API for URI manipulations
(yeah bestie this is the libapa...R::URI(3pm) page from your User Contributed Perl Documentation, section 3pm β we're doing URI stuff today, get comfy π«Ά)
β¨ Synopsis β¨
okay so here's the whole vibe in one go, look at her:
use 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($new_scheme);
$parsed->user(undef);
$parsed->password(undef);
$parsed->hostname($new_hostname);
$parsed->port($new_port);
$parsed->path($new_path);
$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(URI_UNP_REVEALPASSWORD);
print $parsed->unparse(APR::Const::URI_UNP_REVEALPASSWORD);
# what the default port for the ftp protocol?
my $ftp_port = APR::URI::port_of_scheme("ftp");
πΈ Description πΈ
"APR::URI" is literally your bestie for taking URI strings apart, messing with each lil element, and then putting them back together into URIs. parse, vibe, unparse. iconic behavior fr fr π
So here's the thing that trips people up: all APR::URI object accessors take a string or an undef value as an argument. And same energy for the return value. The way that it's SO important to tell apart an empty string and undef β like, they are not the same girl, do not conflate them. For example, say your code was:
my $uri = 'http://example.com/foo?bar#item5';
my $parsed = APR::URI->parse($r->pool, $uri);
Now you decide you no longer want the query and fragment components in the final url. So if you do:
$parsed->fragment('');
$parsed->query('');
followed by:
my $new_uri = parsed->unparse;
the resulting URI will be:
http://example.com/foo?#
which is probably not something that you expected π the separators are still there being messy. In order to get rid of the separators, you must completely unset the fields you don't wanna see. So, if you do:
$parsed->fragment(undef);
$parsed->query(undef);
followed by:
my $new_uri = parsed->unparse;
the resulting URI will be:
http://example.com/foo
And like I said earlier, the same goes for return values, so continuing this example:
my $new_fragment = $parsed->fragment();
my $new_query = $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. β οΈ (yes, careful β that's the whole assignment)
Also make sure you read through "the unparse() section" because various optional flags affect how the deparsed URI is rendered. don't skip it, i'll know π«£
π API π
"APR::URI" provides the following functions and/or methods:
π fragment
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
π hostinfo
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. (she's got her own life, she doesn't keep up with the gossip π)
It's not used when unparse() is called.
π hostname
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
π password
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
π parse
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 parse
- ret:
$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 part http://hostname/path) β the corresponding accessor will return undef.
literally the empty string vs undef thing again!! it's giving character development. remember it π
π path
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 onlyscheme://host
- since: 2.0.00
π rpath
Gets the path minus the path_info
$rpath = $parsed->rpath();
- obj:
$parsed( "APR::URI object" ) - opt arg1:
$newval( string or undef ) - ret:
$oldval( string or undef )- The path minus the path_info
- since: 2.0.00
π port
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 port_of_scheme() to find out the port number for the given scheme().
- since: 2.0.00
π port_of_scheme
Return the default port for a given scheme. The recognized schemes are http, ftp, https, gopher, wais, nntp, snews and prospero. periodt.
$port = APR::URI::port_of_scheme($scheme);
- obj:
$scheme( string )- The scheme string
- ret:
$port(integer)- The default port for this scheme
- since: 2.0.00
π query
Get/set the query string (the part starting after '?' and all the way till 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
π scheme
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
π user
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
π unparse
Unparse the URI components back into a URI string
$new_uri = $parsed->unparse();
$new_uri = $parsed->unparse($flags);
- obj:
$parsed( "APR::URI object" ) - opt arg1:
$flags( theAPR::Const:uriconstants )- By default the constant
"APR::Const::URI_UNP_OMITPASSWORD"is passed. - If you need to pass more than one flag use unary
"|", e.g.:
- By default the constant
$flags = APR::Const::URI_UNP_OMITUSER|APR::Const::URI_UNP_OMITPASSWORD;
- The valid
"flags"constants are listed next
- ret:
$new_uri( 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 (ngl, don't). Instead specify explicitly the ones that you need. All the relevant to this method constants start with "APR::URI_UNP_".
And the available constants are:
"APR::Const::URI_UNP_OMITSITEPART"β Don't show"scheme","user","password","hostname"and"port"components (i.e. if you want only the relative URI)"APR::Const::URI_UNP_OMITUSER"β Hide the"user"component"APR::Const::URI_UNP_OMITPASSWORD"β Hide the"password"component (the default)"APR::Const::URI_UNP_REVEALPASSWORD"β Reveal the"password"component"APR::Const::URI_UNP_OMITPATHINFO"β Don't show"path","query"and"fragment"components"APR::Const::URI_UNP_OMITQUERY"β Don't show"query"and"fragment"components
Notice that some flags overlap. (the overlap is real, don't come for me)
If the optional $flags argument is passed and contains no "APR::Const::URI_UNP_OMITPASSWORD" and no "APR::Const::URI_UNP_REVEALPASSWORD" β the "password" part will be rendered as a literal "XXXXXXXX" string. (censored bestie, she's shy π
)
If the "port" number matches the port_of_scheme(), 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:
- 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://".
- Include the
"password"field (by default it's not revealed)
use APR::Const -compile => qw(URI_UNP_REVEALPASSWORD);
print $parsed->unparse(APR::Const::URI_UNP_REVEALPASSWORD);
Prints:
http://user:pass@example.com/foo?bar#item5
- Show all fields but the last three,
"path","query"and"fragment":
use APR::Const -compile => qw(URI_UNP_REVEALPASSWORD
APR::Const::URI_UNP_OMITPATHINFO);
print $parsed->unparse(
APR::Const::URI_UNP_REVEALPASSWORD|URI_UNP_OMITPATHINFO);
Prints:
http://user:pass@example.com
π¦ See Also π¦
"Apache2::URI", mod_perl 2.0 documentation.
π Copyright π
mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0.
π Authors π
The mod_perl development team and numerous contributors.
okay that's the whole page bestie, you ate that π
β¨ this was libapa...R::URI(3pm) from perl v5.42.3, dated 2026-08-20 β go forth and unparse responsibly, mwah π«Άππ¦
π¦ where this page comes from
- ubuntu stonking: libapache2-mod-perl2 2.0.13-2build3 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms