GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  MOJO::URL (3)

.ds Aq ’

NAME

Mojo::URL - Uniform Resource Locator

CONTENTS

SYNOPSIS



  use Mojo::URL;

  # Parse
  my $url = Mojo::URL->new(foo@example.com:3000/foo">http://sri:foo@example.com:3000/foo?foo=bar#23);
  say $url->scheme;
  say $url->userinfo;
  say $url->host;
  say $url->port;
  say $url->path;
  say $url->query;
  say $url->fragment;

  # Build
  my $url = Mojo::URL->new;
  $url->scheme(http);
  $url->userinfo(sri:foobar);
  $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 <http://tools.ietf.org/html/rfc3986>, RFC 3987 <http://tools.ietf.org/html/rfc3987> and the URL Living Standard <https://url.spec.whatwg.org> 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.



  "http://example.com/a/b?c"
  Mojo::URL->new("/a/b?c")->base(Mojo::URL->new("http://example.com"))->to_abs;



    fragment



  my $fragment = $url->fragment;
  $url         = $url->fragment(XmojoliciousX);



Fragment part of this URL.



  # "yada"
  Mojo::URL->new(http://example.com/foo?bar=baz#yada)->fragment;



    host



  my $host = $url->host;
  $url     = $url->host(127.0.0.1);



Host part of this URL.



  # "example.com"
  Mojo::URL->new(t3st@example.com:8080/foo">http://sri:t3st@example.com:8080/foo)->host;



    port



  my $port = $url->port;
  $url     = $url->port(8080);



Port part of this URL.



  # "8080"
  Mojo::URL->new(t3st@example.com:8080/foo">http://sri:t3st@example.com:8080/foo)->port;



    scheme



  my $scheme = $url->scheme;
  $url       = $url->scheme(http);



Scheme part of this URL.



  # "http"
  Mojo::URL->new(http://example.com/foo)->scheme;



    userinfo



  my $info = $url->userinfo;
  $url     = $url->userinfo(root:X);



Userinfo part of this URL.



  # "sri:t3st"
  Mojo::URL->new(https://sri:t3st@example.com/foo)->userinfo;



METHODS

Mojo::URL inherits all methods from Mojo::Base and implements the following new ones.

    authority



  my $authority = $url->authority;
  $url          = $url->authority(root:%E2%99%A5@localhost:8080);



Authority part of this URL.



  # "root:%E2%99%A5@xn--n3h.net:8080"
  Mojo::URL->new(X@X.net:8080/test">http://root:X@X.net:8080/test)->authority;

  # "root@example.com"
  Mojo::URL->new(root@example.com/test">http://root@example.com/test)->authority;



    clone



  my $url2 = $url->clone;



Clone this URL.

    host_port



  my $host_port = $url->host_port;



Normalized version of host and port.



  # "xn--n3h.net:8080"
  Mojo::URL->new(http://X.net:8080/test)->host_port;

  # "example.com"
  Mojo::URL->new(http://example.com/test)->host_port;



    ihost



  my $ihost = $url->ihost;
  $url      = $url->ihost(xn--bcher-kva.ch);



Host part of this URL in punycode format.



  # "xn--n3h.net"
  Mojo::URL->new(http://X.net)->ihost;

  # "example.com"
  Mojo::URL->new(http://example.com)->ihost;



    is_abs



  my $bool = $url->is_abs;



Check if URL is absolute.



  # True
  Mojo::URL->new(http://example.com)->is_abs;
  Mojo::URL->new(http://example.com/test/index.html)->is_abs;

  # False
  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;
  my $url = Mojo::URL->new(http://127.0.0.1:3000/foo?f=b&baz=2#foo);



Construct a new Mojo::URL object and parse URL if necessary.

    parse



  $url = $url->parse(http://127.0.0.1:3000/foo/bar?fo=o&baz=23#foo);



Parse relative or absolute URL.



  # "/test/123"
  $url->parse(/test/123?foo=bar)->path;

  # "example.com"
  $url->parse(http://example.com/test/123?foo=bar)->host;

  # "sri@example.com"
  $url->parse(mailto:sri@example.com)->path;



    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.



  # "perldoc"
  Mojo::URL->new(http://example.com/perldoc/Mojo)->path->parts->[0];

  # "/perldoc/DOM/HTML"
  Mojo::URL->new(http://example.com/perldoc/Mojo)->path->merge(DOM/HTML);

  # "http://example.com/DOM/HTML"
  Mojo::URL->new(http://example.com/perldoc/Mojo)->path(/DOM/HTML);

  # "http://example.com/perldoc/DOM/HTML"
  Mojo::URL->new(http://example.com/perldoc/Mojo)->path(DOM/HTML);

  # "http://example.com/perldoc/Mojo/DOM/HTML"
  Mojo::URL->new(http://example.com/perldoc/Mojo/)->path(DOM/HTML);



    path_query



  my $path_query = $url->path_query;



Normalized version of path and query.



  # "/test?a=1&b=2"
  Mojo::URL->new(http://example.com/test?a=1&b=2)->path_query;

  # "/"
  Mojo::URL->new(http://example.com/)->path_query;



    protocol



  my $proto = $url->protocol;



Normalized version of scheme.



  # "http"
  Mojo::URL->new(HtTp://example.com)->protocol;



    query



  my $query = $url->query;
  $url      = $url->query([merge => with]);
  $url      = $url->query({append => to});
  $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 merged with merge in Mojo::Parameters, and key/value pairs in a hash reference appended with append in Mojo::Parameters, defaults to a Mojo::Parameters object.



  # "2"
  Mojo::URL->new(http://example.com?a=1&b=2)->query->param(b);

  # "a=2&b=2&c=3"
  Mojo::URL->new(http://example.com?a=1&b=2)->query->merge(a => 2, c => 3);

  # "http://example.com?a=2&c=3"
  Mojo::URL->new(http://example.com?a=1&b=2)->query(a => 2, c => 3);

  # "http://example.com?a=2&a=3"
  Mojo::URL->new(http://example.com?a=1&b=2)->query(a => [2, 3]);

  # "http://example.com?a=2&b=2&c=3"
  Mojo::URL->new(http://example.com?a=1&b=2)->query([a => 2, c => 3]);

  # "http://example.com?b=2"
  Mojo::URL->new(http://example.com?a=1&b=2)->query([a => undef]);

  # "http://example.com?a=1&b=2&a=2&c=3"
  Mojo::URL->new(http://example.com?a=1&b=2)->query({a => 2, c => 3});



    to_abs



  my $abs = $url->to_abs;
  my $abs = $url->to_abs(Mojo::URL->new(http://example.com/foo));



Clone relative URL and turn it into an absolute one using base or provided base URL.



  # "http://example.com/foo/baz.xml?test=123"
  Mojo::URL->new(baz.xml?test=123)
    ->to_abs(Mojo::URL->new(http://example.com/foo/bar.html));

  # "http://example.com/baz.xml?test=123"
  Mojo::URL->new(/baz.xml?test=123)
    ->to_abs(Mojo::URL->new(http://example.com/foo/bar.html));

  # "http://example.com/foo/baz.xml?test=123"
  Mojo::URL->new(//example.com/foo/baz.xml?test=123)
    ->to_abs(Mojo::URL->new(http://example.com/foo/bar.html));



    to_string



  my $str = $url->to_string;



Turn URL into a string.



  # "http://mojolicious.org"
  Mojo::URL->new->scheme(http)->host(mojolicious.org)->to_string;



OPERATORS

Mojo::URL overloads the following operators.

    bool



  my $bool = !!$url;



Always true.

    stringify



  my $str = "$url";



Alias for to_string.

SEE ALSO

Mojolicious, Mojolicious::Guides, <http://mojolicious.org>.
Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 MOJO::URL (3) 2016-03-15

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.