File Coverage

blib/lib/WWW/LogicBoxes/DomainAvailability.pm
Criterion Covered Total %
statement 28 28 100.0
branch n/a
condition n/a
subroutine 10 10 100.0
pod n/a
total 38 38 100.0


line stmt bran cond sub pod time code
1             package WWW::LogicBoxes::DomainAvailability;
2              
3 40     40   534851 use strict;
  40         120  
  40         1333  
4 40     40   248 use warnings;
  40         94  
  40         1119  
5              
6 40     40   1115 use Moose;
  40         545383  
  40         328  
7 40     40   270639 use MooseX::StrictConstructor;
  40         65331  
  40         341  
8 40     40   145735 use MooseX::Aliases;
  40         4520  
  40         317  
9 40     40   320056 use namespace::autoclean;
  40         109  
  40         406  
10              
11 40     40   4926 use WWW::LogicBoxes::Types qw( Bool DomainName Str );
  40         108  
  40         334  
12              
13 40     40   407087 use Mozilla::PublicSuffix;
  40         49864  
  40         10392  
14              
15             our $VERSION = '1.10.0'; # VERSION
16             # ABSTRACT: LogicBoxes Domain Availability Response
17              
18             has name => (
19             is => 'ro',
20             isa => DomainName,
21             required => 1,
22             );
23              
24             has is_available => (
25             is => 'ro',
26             isa => Bool,
27             required => 1,
28             );
29              
30             has sld => (
31             is => 'ro',
32             isa => Str,
33             builder => '_build_sld',
34             lazy => 1,
35             init_arg => undef,
36             );
37              
38             has public_suffix => (
39             is => 'ro',
40             isa => Str,
41             alias => 'tld',
42             builder => '_build_public_suffix',
43             lazy => 1,
44             init_arg => undef,
45             );
46              
47             ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
48             sub _build_sld {
49 4     4   7 my $self = shift;
50              
51 4         114 return substr( $self->name, 0, length( $self->name ) - ( length( $self->public_suffix ) + 1 ) );
52             }
53             ## use critic
54              
55             ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
56             sub _build_public_suffix {
57 4     4   6 my $self = shift;
58              
59 4         105 return Mozilla::PublicSuffix::public_suffix( $self->name );
60             }
61             ## use critic
62              
63             __PACKAGE__->meta->make_immutable;
64              
65             1;
66              
67             __END__
68             =pod
69              
70             =head1 NAME
71              
72             WWW::LogicBoxes::DomainAvailability
73              
74             =head1 SYNOPSIS
75              
76             use WWW::LogicBoxes;
77              
78             my $logic_boxes = WWW::LogicBoxes->new( ... );
79              
80             my $domain_availabilities = $logic_boxes->check_domain_availability(
81             slds => [qw( cpan drzigman brainstormincubator ],
82             tlds => [qw( com net org )],
83             suggestions => 0,
84             );
85              
86             for my $domain_availability (@{ $domain_availabilities }) {
87             if ( $domain_availability->is_available ) {
88             print 'Domain: ' . $domain_availability->name . " is available! :) \n";
89             }
90             else {
91             print 'Domain: ' . $domain_availability->name . " is not available! :( \n";
92             }
93             }
94              
95             =head1 DESCRIPTION
96              
97             Contains details about the availability of a domain.
98              
99             =head1 ATTRIBUTES
100              
101             =head2 B<name>
102              
103             The full domain name (test-domain.com).
104              
105             =head2 B<is_available>
106              
107             Boolean indicating if this domain is available for registration.
108              
109             =head2 sld
110              
111             The portion of the domain name excluding the public_suffix, (test-domain).
112              
113             =head2 public_suffix
114              
115             The "root" of the domain (.com). There is an alias of tld to this attribute.
116              
117             B<NOTE> For domains like test-domain.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/>
118              
119             =cut