Web::Host
Host names for the Web
SYNOPSIS
use Web::Host;
$host = Web::Host->parse_string ("MyDomain.test");
warn $host->is_domain;
warn $host->is_ip;
warn $host->to_ascii;
warn $host->to_unicode;
DESCRIPTION
The Web::Host object represents a host, i.e. a domain, an IPv4 address, or an IPv6 address.
METHODS
Following methods are available:
$host = Web::Host->parse_string ($string)-
Parse the string and return a
Web::Hostobject for the host. The argument must be a domain, an IPv4 address, or an IPv6 address enclosed by[and]. It does not have to be canonicalized. It can be an IDN. If the argument is not a valid host, anundefvalue is returned instead. ($host, $port) = Web::Host->parse_hostport_string ($string)-
Parse the string as a host optionally followed by
:and port number and return a pair of aWeb::Hostobject for the host and an integer for the port. If the argument is not a valid host and port string, anundefandundefpair is returned instead. $host = Web::Host->new_from_packed_addr ($bytes)-
Create a
Web::Hostobject for the "packed" IP address. The argument must be a byte string of length 4 or 16. See alsopacked_addr. $boolean = $host->is_domain-
Return whether the host is a domain or not.
$boolean = $host->is_ip-
Return whether the host is an IP address or not.
$boolean = $host->is_ipv4-
Return whether the host is an IPv4 address or not.
$boolean = $host->is_ipv6-
Return whether the host is an IPv6 address or not.
$host1->equals ($host2)-
Return whether two hosts are equal or not. They are equal if and only if their serializations are equal, by definition.
$string = $host->stringify$string = $host->to_ascii$string = $host->TO_JSON-
Serialize the host, using the host serializer of the URL Standard. The result is canonicalized. Any IDN is converted into its Punycode form. IPv6 addresses are enclosed in
[and].Note that JavaScript code
URL.domainToASCII ($domain)(where $domain is a Unicode string) is equivalent to the following code:my $host = Web::Host->parse_string ($domain); if ($host->is_domain) { return $host->to_ascii; } else { return ''; } $string = $host->to_unicode-
Serialize the host, but decode Punycode-encoded labels in the host whenever possible.
Note that JavaScript code
URL.domainToUnicode ($domain)(where $domain is a Unicode string) is equivalent to the following code:my $host = Web::Host->parse_string ($domain); if ($host->is_domain) { return $host->to_unicode; } else { return ''; } $bytes = $host->packed_addr-
Return the "packed" representation of the IP address, i.e. bytes of length 4 (if IPv4 address) or 16 (if IPv6 address) representing the address in network byte order (big endian). If the host is a domain,
undefis returned instead. $string = $host->text_addr-
Return the textual representation of the IP address, serialized using the IPv4 or IPv6 serializer of the URL Standard. The result is canonicalized. IPv6 addresses are not enclosed by
[and]. If the host is a domain,undefis returned instead.
SPECIFICATIONS
URL Standard <https://url.spec.whatwg.org/>.
UTS #46: Unicode IDNA Compatibility Processing <https://www.unicode.org/reports/tr46/>.
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.