Scroll to navigation

Domain::PublicSuffix(3) User Contributed Perl Documentation Domain::PublicSuffix(3)


Domain::PublicSuffix - Parse a domain down to root


 use Domain::PublicSuffix;
 my $suffix = Domain::PublicSuffix->new({
   'data_file' => '/tmp/effective_tld_names.dat'
 my $root = $suffix->get_root_domain('');
 # $root now contains ""
 $root = $suffix->get_root_domain('');
 # $root now contains
 my $suf = $suffix->suffix();
 # $suf now contains
 my $tld = $suffix->tld();
 # $tld now contains uk


This module utilizes the "effective_tld_names.dat" provided by Mozilla as a way to effectively reduce a fully qualified domain name down to the absolute root. The Mozilla PublicSuffix file is an open source, fully documented format that shows absolute root TLDs, primarily for Mozilla's browser products to be able to determine how far a cookie's security boundaries go.

This module will attempt to search etc directories in /usr/share/publicsuffix, /usr, /usr/local, and /opt/local for the effective_tld_names.dat file. If a file is not found, a default file is loaded from Domain::PublicSuffix::Default, which is current at the time of the module's release. You can override the data file path by giving the new() method a 'data_file' argument.

When creating a new PublicSuffix object, the module will load the data file as specified, and use the internal structure to parse each domain sent to the get_root_domain method. To re-parse the file, you must destroy and create a new object, or execute the _parse_data_file method directly, though that is not recommended.


On unsuccessful parse, contains a human-readable error string.
Returns the effective tld of the last parsed domain. For the domain '', this would return ''.
Returns the true DNS tld of the last parsed domain. For the domain '', this would return 'uk'.


Instantiate a PublicSuffix object. It is best to instantiate an object and continue calling get_root_domain instead of continually recreating the object, as the data file is read and parsed on instantiation.

Can take a hashref of arguments:

A fully qualified path, to override the effective_tld_names.dat file.
Use the provided publicsuffix file, do not search for any other files.
A flag to indicate that underscores should be allowed in hostnames (contra to the RFCs). Default: undef.
A flag to indicate that unlisted TLDs should be passed through. This follows the spec as listed on, but is not how this module works by default, or before 0.16. Default: undef
Given a fully qualified domain name, return the parsed root domain name. Returns undefined if an error occurs parsing the given domain, and fills the error accessor with a human-readable error string.



Please report any bugs or feature requests to "bug-domain-publicsuffix at", or through the web interface at <>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

  perldoc Domain::PublicSuffix

You can also look for information at:


dkg: Daniel Kahn Gillmor

gavinc: Gavin Carr

jwieland: Jason Wieland


Copyright 2008-2020 Nicholas Melnick, "nick at".

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

2024-03-08 perl v5.40.0