| 1 | package WWW::eNom::Role::ParseDomain; | ||
| 2 | |||
| 3 | 66 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 66 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 66 | ▶ | use Moose::Role; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 66 | ▶ | use MooseX::Aliases; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | 66 | ▶ | use WWW::eNom::Types qw( Str ); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | |||
| 11 | 66 | ▶ | use Mozilla::PublicSuffix; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | |||
| 13 | 66 | requires 'name'; | |
| 14 | |||
| 15 | 66 | our $VERSION = 'v2.6.0'; # VERSION | |
| 16 | # ABSTRACT: Parse a domain into sld and public_suffix/tld | ||
| 17 | |||
| 18 | 66 | has 'sld' => ( | |
| 19 | is => 'ro', | ||
| 20 | isa => Str, | ||
| 21 | builder => '_build_sld', | ||
| 22 | lazy => 1, | ||
| 23 | init_arg => undef, | ||
| 24 | ); | ||
| 25 | |||
| 26 | 66 | has 'public_suffix' => ( | |
| 27 | is => 'ro', | ||
| 28 | isa => Str, | ||
| 29 | alias => 'tld', | ||
| 30 | builder => '_build_public_suffix', | ||
| 31 | lazy => 1, | ||
| 32 | init_arg => undef, | ||
| 33 | ); | ||
| 34 | |||
| 35 | sub _build_sld { | ||
| 36 | 4 | ▶ | my $self = shift; |
|
Subroutine
_build_sld: called CC=1 SCAR=0.0
| |||
| 37 | |||
| 38 | 4 | return substr( $self->name, 0, length( $self->name ) - ( length( $self->public_suffix ) + 1 ) ); | |
| 39 | } | ||
| 40 | |||
| 41 | sub _build_public_suffix { | ||
| 42 | 6 | ▶ | my $self = shift; |
|
Subroutine
_build_public_suffix: called CC=1 SCAR=0.0
| |||
| 43 | |||
| 44 | 6 | return Mozilla::PublicSuffix::public_suffix( $self->name ); | |
| 45 | } | ||
| 46 | |||
| 47 | 66 | 1; | |
| 48 | |||
| 49 | __END__ | ||
| 50 | |||
| 51 | =pod | ||
| 52 | |||
| 53 | =head1 NAME | ||
| 54 | |||
| 55 | WWW::eNom::Role::ParseDomain - Parse a domain into sld and public_suffix/tld | ||
| 56 | |||
| 57 | =head1 REQUIRES | ||
| 58 | |||
| 59 | =over 4 | ||
| 60 | |||
| 61 | =item name | ||
| 62 | |||
| 63 | =back | ||
| 64 | |||
| 65 | =head1 DESCRIPTION | ||
| 66 | |||
| 67 | This role is consumed by objects that have a domain name and adds to the consuming object the ability to split that domain into sld and public_suffix/tld. This is critically important because most of L<eNom|https://www.enom.com>'s API expects the SLD and TLD to be sent as different parameters. | ||
| 68 | |||
| 69 | =head1 ATTRIBUTES | ||
| 70 | |||
| 71 | =head2 sld | ||
| 72 | |||
| 73 | The SLD of the domain. For google.co.uk this value would be google. | ||
| 74 | |||
| 75 | B<NOTE> this is lazy built with an init_arg of undef. | ||
| 76 | |||
| 77 | =head2 public_suffix | ||
| 78 | |||
| 79 | The public_suffix of the domain (what some folks incorrectly call the TLD). For domains like google.co.uk the public_suffix is .co.uk. The public suffix is what is available for someone to actually register. For additional information between the distinction between Top Level Domain and Public Suffix please see L<https://publicsuffix.org/learn/> | ||
| 80 | |||
| 81 | An alias of 'tld' is also provided if you really wish to refer to this as the TLD. | ||
| 82 | |||
| 83 | B<NOTE> this is lazy built with an init_arg of undef. | ||
| 84 | |||
| 85 | =cut | ||