20.5.1.1. URI methods
The following methods give you access to components of a URI. These
methods will return a string, unless the URI component is invalid, in
which case undef is returned. Bear in mind that an
empty string ("") is not equivalent
to an undefined value.
new($uri, [$scheme])
Constructor. $uri is
given as an argument with the optional
$scheme.
new removes additional whitespace, double quotes,
and arrows from the URL.
$scheme is used only
when $str is a relative
URI; it is a simple string that denotes the scheme or an absolute URI
object. $str will be
treated like a generic URI if
$scheme isn't defined.
URI::file->new($file, [$os])
Constructs a new file URI from a filename.
URI::file->new_abs($file, [$os])
Constructs a new absolute file URI from a filename.
abs($base_uri)
Returns an absolute URI reference. If
$uri is already
absolute, then a reference to
$uri is returned.
abs returns a new absolute URI that contains
$uri and
$base_uri if
$uri is relative.
as_string
Returns a URI object as a plain string.
authority([$auth])
Sets and gets the authority component of the
$uri. This component
will be escaped.
canonical
Returns a normalized version of the URI. This includes lowercasing
the scheme and hostname components, as well as removing an explicit
port specification (if it mtaches the default port).
canonical will return the original
$uri if
$uri was already in the
correct form.
clone
Returns a copy of the URI.
URI::file->cwd
Returns the current working directory as a file URI.
default_port()
Returns the default port of the URI scheme that
$uri belongs to. You
cannot change the default port for a scheme.
fragment([$new_frag])
Returns the fragment identifier of a URI reference as an escaped
string.
host([$new_host])
Sets and gets the unescaped hostname. To specify a different port:
$new_host = "hostname:port_number"
host_port([$new_host_port])
Sets and gets the host and port as a single unit. Hostname and port
are colon-separated.
new_abs($str, $base_uri)
Creates a new absolute URI object.
$str represents the
absolute URI, and
$base_uri represents
the relative URI.
opaque([$new_opaque_value])
Sets and gets the scheme-specific part of
$uri.
path([$path])
Sets and gets the escaped path component of
$uri. Returns empty
string ("") if there is no path.
path([$new_path])
Gets and sets the same value as opaque, unless the
URI supports the generic syntax for heirarchical namespaces.
path returns the part of the URI between the
hostname and the fragment.
path_query([$path_here])
Sets and gets the escapted path and query components.
path_segments([$seg])
Sets and gets the path. In a scalar content,
path_segments is equivalent to
path. In a list contents,
path_segments returns the unescaped path segments
that make up the path.
port([$new_port])
Sets and gets the port, which is an integer. If
$new_port is not
defined, then the default port of the URI scheme will be returned.
query([$q])
Sets and gets the escaped query component of
$ uri .
query_form([$key => $val])
Sets and gets query components that use the urlencoded format.
query_keywords([$keywords])
Sets and gets query components that use keywords separated by a
+.
rel($base_uri)
Returns a relative URI reference, if one exists. Otherwise,
$uri is returned.
scheme([$some_scheme])
Sets and gets the scheme part of the URI. Such values include:
data, file,
ftp, gopher,
http, https,
ldap, mailto,
news, nntp,
pop, rlogin,
rsync, snews,
telnet, and ssh. In the case of
relative URIs, scheme will return
undef; otherwise, scheme will
return the scheme in lowercase. With
$some_scheme,
scheme will set the scheme of the current URI.
scheme will die if the scheme isn't supported, or
if it contains non-US-ASCII characters.
userinfo([$new_userinfo])
Sets and gets the escaped
"userinfo" part of the authority
component (of the URI). Often, the userinfo will appear as a username
and password separated by a colon. Bear in mind that sending a
password in the clear is a bad idea.