The manakai project

Web::URL

URL record API

SYNOPSIS

  use Web::URL;
  my $url = Web::URL->parse_string ($input_string, $base_url_record);
  warn $url->stringify;

SYNOPSIS

The Web::URL object represents a URL record.

METHODS

There are following methods:

$url = Web::URL->parse_string ($input_string, $base_url_record)

Parse a string and return a URL record object (Web::URL) for it.

The first argument is the string to be parsed as a URL string.

The second argument is a URL record, which is used as the base URL. If undef is specified, about:blank is used as the base URL.

If the parsing failed, the method returns undef.

$string = $url->scheme

Return the scheme component of the URL, canonicalized (i.e. in lowercase).

$boolean = $url->is_http_s

Return whether the URL's scheme is an HTTP(S) scheme or not, i.e. whether either http or https or not.

$string = $url->username

Return the username component of the URL. If the URL has no explicit username component, the empty string is returned.

$string = $url->password

Return the password component of the URL. If the URL has no explicit password component, the empty string is returned.

$host = $url->host

Return the host (Web::Host) of the URL, if any, or undef.

$string = $url->port

Return the port component of the URL, if any, or undef.

$string = $url->hostport

Serialize the host and port components of the URL, if any, or undef.

$string = $url->path

Serialize the path component of the URL.

$string = $url->pathquery

Serialize the path and query components of the URL.

$string = $url->query

Return the query component of the URL, if any, or undef. It does not contain any ? prefix.

$url->set_query_params ($params, append => $boolean)

Set the query parameters, in the application/x-www-form-urlencoded syntax with UTF-8.

If the append flag is set to a true value, any existing query component of the URL is preserved and the parameters are appended with separator &.

If the append flag is set to a false value, any existing query component of the URL is discarded.

This method mutates the URL record object.

$string = $url->fragment

Return the fragment component of the URL, if any, or undef. It does not contain any # prefix.

$origin = $url->get_origin

Get a new origin object (Web::Origin) representing the origin of the URL.

$string = $url->stringify
$string = $url->TO_JSON

Serialize the URL record as a string.

$string = $url->stringify_without_fragment

Serialize the URL record as a string, excluding any fragment component.

$string = $url->originpathquery

Serialize the URL record as a string, excluding any userinfo and fragment components.

This method can be used to obtain a value for HTTP request-target or Referer: and document.referrer.

$string = $url->originpath

Serialize the URL record as a string, excluding any userinfo, query, and fragment components.

This method can be used to obtain a value for OAuth 1.0 signature generation.

$url2 = $url->clone

Create another URL record object which has the same components as the URL record.

SPECIFICATION

URL Standard <https://url.spec.whatwg.org/>.

However, the URL parsing does not support URL Standard yet; the old spec implemented by the current version of the URL parser module is available at <https://github.com/wakaba/tests-web-url/blob/master/spec.txt>.

AUTHOR

Wakaba <wakaba@suikawiki.org>.

LICENSE

Copyright 2016-2017 Wakaba <wakaba@suikawiki.org>.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.