File Coverage

blib/lib/WWW/DNSMadeEasy/Domain.pm
Criterion Covered Total %
statement 17 33 51.5
branch n/a
condition n/a
subroutine 6 15 40.0
pod 8 12 66.6
total 31 60 51.6


line stmt bran cond sub pod time code
1             package WWW::DNSMadeEasy::Domain;
2             our $VERSION = '0.100';
3             our $AUTHORITY = 'cpan:GETTY';
4             # ABSTRACT: A domain in the DNSMadeEasy API
5              
6 8     8   51 use Moo;
  8         17  
  8         102  
7 8     8   7409 use WWW::DNSMadeEasy::Domain::Record;
  8         59  
  8         5540  
8              
9             has name => (
10             # isa => 'Str',
11             is => 'ro',
12             required => 1,
13             );
14              
15             has dme => (
16             # isa => 'WWW::DNSMadeEasy',
17             is => 'ro',
18             required => 1,
19             );
20              
21             sub create {
22 0     0 0 0 my ( $class, @args ) = @_;
23 0         0 my $domain = $class->new(@args);
24 0         0 $domain->put;
25 0         0 return $domain;
26             }
27              
28             sub path {
29 4     4 0 7 my ( $self ) = @_;
30 4         18 $self->dme->path_domains.'/'.$self->name;
31             }
32              
33             sub delete {
34 0     0 1 0 my ( $self ) = @_;
35 0         0 $self->dme->request('DELETE',$self->path);
36             }
37              
38             sub put {
39 0     0 1 0 my ( $self ) = @_;
40 0         0 $self->dme->request('PUT',$self->path);
41             }
42              
43 4     4 0 10 sub path_records { shift->path.'/records' }
44              
45 0     0 1 0 sub name_server { shift->response->data->{nameServer} }
46 0     0 1 0 sub gtd_enabled { shift->response->data->{gtdEnabled} }
47 0     0 1 0 sub vanity_name_servers { shift->response->data->{vanityNameServers} }
48 0     0 1 0 sub vanity_id { shift->response->data->{vanityId} }
49              
50             has response => (
51             is => 'ro',
52             builder => '_build_response',
53             lazy => 1,
54             );
55              
56             sub _build_response {
57 0     0   0 my ( $self ) = @_;
58 0         0 $self->dme->request('GET',$self->path);
59             }
60              
61             sub create_record {
62 1     1 1 25 my ( $self, $data ) = @_;
63              
64 1         5 my $post_response = $self->dme->request('POST',$self->path_records,$data);
65              
66             return WWW::DNSMadeEasy::Domain::Record->new({
67             domain => $self,
68             id => $post_response->data->{id},
69 1         5 response => $post_response,
70             });
71             }
72              
73             sub post {
74 0     0 0 0 my ( $self ) = @_;
75 0         0 $self->dme->request('POST',$self->path);
76             }
77              
78             sub all_records {
79 2     2 1 77 my ( $self ) = @_;
80              
81 2         12 my $data = $self->dme->request('GET', $self->path_records)->as_hashref;
82              
83 2         38 my @records;
84             push @records, WWW::DNSMadeEasy::Domain::Record->new({
85             domain => $self,
86             id => $_->{id},
87             as_hashref => $_,
88 2         28 }) for @$data;
89            
90 2         1251 return @records;
91             }
92              
93             1;
94              
95             __END__
96              
97             =pod
98              
99             =encoding UTF-8
100              
101             =head1 NAME
102              
103             WWW::DNSMadeEasy::Domain - A domain in the DNSMadeEasy API
104              
105             =head1 VERSION
106              
107             version 0.100
108              
109             =head1 ATTRIBUTES
110              
111             =head2 name
112              
113             Name of the domain
114              
115             =head2 dme
116              
117             L<WWW::DNSMadeEasy> object
118              
119             =head2 obj
120              
121             Hash object representation given by DNSMadeEasy.
122              
123             =head1 METHODS
124              
125             =head2 $obj->put
126              
127             =head2 $obj->delete
128              
129             =head2 $obj->all_records
130              
131             =head2 $obj->create_record
132              
133             =head2 $obj->name_server
134              
135             =head2 $obj->gtd_enabled
136              
137             =head2 $obj->vanity_name_servers
138              
139             =head2 $obj->vanity_id
140              
141             =head1 ATTRIBUTES
142              
143             =head1 SUPPORT
144              
145             IRC
146              
147             Join #duckduckgo on irc.freenode.net and highlight Getty or /msg me.
148              
149             Repository
150              
151             http://github.com/Getty/p5-www-dnsmadeeasy
152             Pull request and additional contributors are welcome
153              
154             Issue Tracker
155              
156             http://github.com/Getty/p5-www-dnsmadeeasy/issues
157              
158             =for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
159              
160             =head1 SUPPORT
161              
162             =head2 Source Code
163              
164             The code is open to the world, and available for you to hack on. Please feel free to browse it and play
165             with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
166             from your repository :)
167              
168             L<https://github.com/Getty/p5-www-dnsmadeeasy>
169              
170             git clone https://github.com/Getty/p5-www-dnsmadeeasy.git
171              
172             =head1 AUTHOR
173              
174             Torsten Raudssus <torsten@raudssus.de>
175              
176             =head1 COPYRIGHT AND LICENSE
177              
178             This software is copyright (c) 2012 by L<Torsten Raudssus|https://raudssus.de/>.
179              
180             This is free software; you can redistribute it and/or modify it under
181             the same terms as the Perl 5 programming language system itself.
182              
183             =cut