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 pass min_suffix in %args to specify the minimal suffix β€” the default is 1.
  • class->from_string(string,%args) β€” Returns an object with configuration from a string. Peep the default method for what %args wants, iykyk.
  • class->from_file( file name| file handle, %args ) β€” Returns an object with configuration from a file or a file handle. Again, default has the %args tea.
  • $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 $add parts of the non-tld part onto the tld β€” so with $add=1 it'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 have L<Domain::PublicSuffix> and L<Mozilla::PublicSuffix>. A: Because the public suffix data change more often than these modules do, IO::Socket::SSL needs 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