NAME
Mojo::URL - Uniform Resource Locator
SYNOPSIS
say $url ->scheme;
say $url ->userinfo;
say $url ->host;
say $url ->port;
say $url ->path;
say $url ->query;
say $url ->fragment;
my $url = Mojo::URL->new;
$url ->scheme( 'http' );
$url ->host( 'example.com' );
$url ->port(3000);
$url ->path( '/foo/bar' );
$url ->query( foo => 'bar' );
$url ->fragment(23);
say "$url" ;
|
DESCRIPTION
Mojo::URL implements a subset of RFC 3986, RFC 3987 and the URL Living Standard for Uniform Resource Locators with support for IDNA and IRIs.
ATTRIBUTES
Mojo::URL implements the following attributes.
base
my $base = $url ->base;
$url = $url ->base(Mojo::URL->new);
|
Base of this URL, defaults to a Mojo::URL object.
fragment
my $fragment = $url ->fragment;
$url = $url ->fragment( '♥mojolicious♥' );
|
Fragment part of this URL.
host
my $host = $url ->host;
$url = $url ->host( '127.0.0.1' );
|
Host part of this URL.
port
my $port = $url ->port;
$url = $url ->port(8080);
|
Port part of this URL.
scheme
my $scheme = $url ->scheme;
$url = $url ->scheme( 'http' );
|
Scheme part of this URL.
userinfo
my $info = $url ->userinfo;
$url = $url ->userinfo( 'root:♥' );
|
Userinfo part of this URL.
METHODS
Mojo::URL inherits all methods from Mojo::Base and implements the following new ones.
clone
Return a new Mojo::URL object cloned from this URL.
host_port
my $host_port = $url ->host_port;
$url = $url ->host_port( 'example.com:8080' );
|
Normalized version of "host" and "port".
Mojo::URL->new( 'http://☃.net:8080/test' )->host_port; |
ihost
my $ihost = $url ->ihost;
$url = $url ->ihost( 'xn--bcher-kva.ch' );
|
Host part of this URL in punycode format.
Mojo::URL->new( 'http://☃.net' )->ihost; |
is_abs
Check if URL is absolute.
Mojo::URL->new( 'test/index.html' )->is_abs;
Mojo::URL->new( '/test/index.html' )->is_abs;
Mojo::URL->new( '//example.com/test/index.html' )->is_abs;
|
new
my $url = Mojo::URL->new;
|
Construct a new Mojo::URL object and "parse" URL if necessary.
parse
Parse relative or absolute URL.
$url ->parse( '/test/123?foo=bar' )->path;
$url ->parse( 'mailto:sri@example.com' )->path;
|
password
my $password = $url ->password;
|
Password part of "userinfo".
path
my $path = $url ->path;
$url = $url ->path( 'foo/bar' );
$url = $url ->path( '/foo/bar' );
$url = $url ->path(Mojo::Path->new);
|
Path part of this URL, relative paths will be merged with "merge" in Mojo::Path, defaults to a Mojo::Path object.
path_query
my $path_query = $url ->path_query;
$url = $url ->path_query( '/foo/bar?a=1&b=2' );
|
Normalized version of "path" and "query".
protocol
my $proto = $url ->protocol;
|
Normalized version of "scheme".
query
my $query = $url ->query;
$url = $url ->query({ merge => 'to' });
$url = $url ->query([ append => 'with' ]);
$url = $url ->query( replace => 'with' );
$url = $url ->query( 'a=1&b=2' );
$url = $url ->query(Mojo::Parameters->new);
|
Query part of this URL, key/value pairs in an array reference will be appended with "append" in Mojo::Parameters, and key/value pairs in a hash reference merged with "merge" in Mojo::Parameters, defaults to a Mojo::Parameters object.
to_abs
Return a new Mojo::URL object cloned from this relative URL and turn it into an absolute one using "base" or provided base URL.
Mojo::URL->new( 'baz.xml?test=123' )
Mojo::URL->new( '/baz.xml?test=123' )
Mojo::URL->new( '//example.com/foo/baz.xml?test=123' )
|
to_string
my $str = $url ->to_string;
|
Turn URL into a string. Note that "userinfo" will not be included for security reasons.
Mojo::URL->new->scheme( 'http' )->host( 'mojolicious.org' )->to_string;
|
to_unsafe_string
my $str = $url ->to_unsafe_string;
|
Same as "to_string", but includes "userinfo".
username
my $username = $url ->username;
|
Username part of "userinfo".
OPERATORS
Mojo::URL overloads the following operators.
bool
Always true.
stringify
Alias for "to_string".
SEE ALSO
Mojolicious, Mojolicious::Guides, https://mojolicious.org.