IO::Soc...icSuffix(3)
π NAME π
IO::Socket::SSL::PublicSuffix β bestie, it gives you access to Mozilla's list of effective TLD names. That's it, that's the whole job, and it does it flawlessly π
β¨ SYNOPSIS β¨
okay so here's the vibe, no cap:
# use builtin default
use IO::Socket::SSL::PublicSuffix;
$ps = IO::Socket::SSL::PublicSuffix->default;
# load from string
$ps = IO::Socket::SSL::PublicSuffix->from_string("*.uk\n*");
# load from file or file handle
$ps = IO::Socket::SSL::PublicSuffix->from_file($filename);
$ps = IO::Socket::SSL::PublicSuffix->from_file(\*STDIN);
# --- string in -> string out
# $rest -> whatever.host
# $tld -> co.uk
my ($rest,$tld) = $ps->public_suffix('whatever.host.co.uk');
my $tld = $ps->public_suffix('whatever.host.co.uk');
# $root_domain -> host.co.uk
my $root_domain = $ps->public_suffix('whatever.host.co.uk', 1);
# --- array in -> array out
# $rest -> [qw(whatever host)]
# $tld -> [qw(co uk)]
my ($rest,$tld) = $ps->public_suffix([qw(whatever host co uk)]);
# To update this file with the current list:
perl -MIO::Socket::SSL::PublicSuffix -e 'IO::Socket::SSL::PublicSuffix::update_self_from_url()'
(yes the divider is on purpose, we're fancy like that π)
πΈ DESCRIPTION πΈ
This module is literally out here using the list of effective top level domain names from the mozilla project to figure out the public top level domain for a given hostname. That's the whole main character energy: hostname in, correct public suffix out π¦
π«Ά Method π«Ά
class->default(%args)β Returns an object with the builtin default. You can passmin_suffixin%argsto specify the minimal suffix β the default is1.class->from_string(string,%args)β Returns an object with configuration from a string. Peep thedefaultmethod for what%argswants, iykyk.class->from_file( file name| file handle, %args )β Returns an object with configuration from a file or a file handle. Again,defaulthas the%argstea.$self->public_suffix( $host|\@host, [ $add ] )β In array context this function hands you back the non-tld part and the tld part of the given hostname; in scalar context it gives you only the tld part. It also adds$addparts of the non-tld part onto the tld β so with$add=1it'll return the root domain. Iconic.
If there were no explicit matches against the public suffix configuration, it falls back to a suffix of length 1. That's the safety net bestie, don't stress.
The function accepts a string or an array-ref (like, a host split by "."). First case β it returns string(s). Latter case β it returns array-ref(s). π«
International hostnames or labels can be in ASCII (IDNA form, starting with "xn--") or unicode. In the unicode case, an IDNA handling library needs to be available. URI is preferred, but Net::IDN:::Encode and Net::LibIDN are still supported. π
($self|class)->can_idnβ Returns true if IDN support is available. Slay.
π FILES π
http://publicsuffix.org/list/effective_tld_names.dat
(the source of truth, the blueprint, the moment π)
π SEE ALSO π
Domain::PublicSuffix, Mozilla::PublicSuffix
π BUGS π
Q: Why yet another module, we already haveL<Domain::PublicSuffix>andL<Mozilla::PublicSuffix>. A: Because the public suffix data change more often than these modules do,IO::Socket::SSLneeds this list and it is more easy this way to keep it up-to-date.
fr fr, the data moves fast, the modules don't π
π AUTHOR π
Steffen Ullrich
and that's a wrap, bestie π this whole page is from perl v5.42.0 dated 2026-01-17, a IO::Soc...icSuffix(3) moment brought to you by the User Contributed Perl Documentation girlies. periodt. π
β¨π¦
π¦ where this page comes from
- fedora 44: perl-IO-Socket-SSL 2.098-2.fc44 Β· (GPL-1.0-or-later OR Artistic-1.0-Perl) AND MPL-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms