NAME

ParseUtil::Domain - Utility for parsing a domain name into its components.

SYNOPSIS

use ParseUtil::Domain ':parse';

  my $processed = parse_domain("somedomain.com");
  #$processed:
  #{ 
      #domain => 'somedomain',
      #domain_ace => 'somedomain',
      #zone => 'com',
      #zone_ace => 'com'
  #}

DESCRIPTION

A tool for parsing domain names. This module makes use of the data provided by the Public Suffix List (http://publicsuffix.org/list/) to parse tlds.

It also provides respective puny encoded and decoded versions of the parsed domain.

INTERFACE

parse_domain

parse_domain(string)
Examples:
  1. parse_domain('somedomain.com');

   Result:
   {
       domain     => 'somedomain',
       zone       => 'com',
       domain_ace => 'somedomain',
       zone_ace   => 'com'
   }

 2. parse_domain('test.xn--o3cw4h');

   Result: 
   {
       domain     => 'test',
       zone       => 'ไทย',
       domain_ace => 'test',
       zone_ace   => 'xn--o3cw4h'
   }

 3. parse_domain('bloß.co.at');

   Result:
   {
       domain     => 'bloss',
       zone       => 'co.at',
       domain_ace => 'bloss',
       zone_ace   => 'co.at'
   }

 4. parse_domain('bloß.de');

   Result:
   {
       domain     => 'bloß',
       zone       => 'de',
       domain_ace => 'xn--blo-7ka',
       zone_ace   => 'de'
   }

puny_convert

Toggles a domain between puny encoded and decoded versions.

use ParseUtil::Domain ':simple';

my $result = puny_convert('bloß.de');
# $result: xn--blo-7ka.de

my $reverse = puny_convert('xn--blo-7ka.de');
# $reverse: bloß.de

DEPENDENCIES

Net::IDN::Encode
Net::IDN::Punycode
Regexp::Assemble::Compressed
The Public Suffix List at http://publicsuffix.org/list/

CHANGES

  • gTLDs

    .bcm, .design, .kiwi and several others

  • Added a subroutine puny_convert that toggles back and forth between puny encoded and decoded versions of a domain.

  • Added a script called punyconvert for command line conversion.

  • croak whenever the domain can't be mapped back to itself.