File Coverage

blib/lib/WWW/DNSMadeEasy/ManagedDomain/Record.pm
Criterion Covered Total %
statement 16 61 26.2
branch 0 4 0.0
condition 0 6 0.0
subroutine 9 32 28.1
pod 25 27 92.5
total 50 130 38.4


line stmt bran cond sub pod time code
1             package WWW::DNSMadeEasy::ManagedDomain::Record;
2             our $VERSION = '0.100';
3             our $AUTHORITY = 'cpan:GETTY';
4             # ABSTRACT: A managed domain record in the DNSMadeEasy API
5              
6 8     8   60 use Moo;
  8         21  
  8         71  
7 8     8   4056 use String::CamelSnakeKebab qw/lower_camel_case/;
  8         37  
  8         55  
8 8     8   7001 use WWW::DNSMadeEasy::Monitor;
  8         89  
  8         9830  
9              
10             has domain => (is => 'ro', required => 1, handles => {path => 'records_path'});
11             has dme => (is => 'lazy', handles => ['request']);
12             has as_hashref => (is => 'rw', builder => 1, lazy => 1, clearer => 1);
13             has response => (is => 'rw');
14              
15 1     1   110 sub _build_dme { shift->domain->dme }
16 1     1   15 sub _build_as_hashref { shift->response->as_hashref }
17              
18 0     0 1 0 sub description { shift->as_hashref->{description} }
19 0     0 1 0 sub dynamic_dns { shift->as_hashref->{dynamicDns} }
20 0     0 1 0 sub failed { shift->as_hashref->{failed} }
21 0     0 1 0 sub failover { shift->as_hashref->{failover} }
22 0     0 1 0 sub gtd_location { shift->as_hashref->{gtdLocation} }
23 0     0 1 0 sub hard_link { shift->as_hashref->{hardLink} }
24 4     4 1 11137 sub id { shift->as_hashref->{id} }
25 0     0 1 0 sub keywords { shift->as_hashref->{keywords} }
26 0     0 1 0 sub monitor { shift->as_hashref->{monitor} }
27 0     0 1 0 sub mxLevel { shift->as_hashref->{mxLevel} }
28 3     3 1 1065 sub name { shift->as_hashref->{name} }
29 0     0 1 0 sub password { shift->as_hashref->{password} }
30 0     0 1 0 sub port { shift->as_hashref->{port} }
31 0     0 1 0 sub priority { shift->as_hashref->{priority} }
32 0     0 1 0 sub redirect_type { shift->as_hashref->{redirectType} }
33 0     0 1 0 sub source { shift->as_hashref->{source} }
34 0     0 1 0 sub source_id { shift->as_hashref->{source_id} }
35 0     0 1 0 sub title { shift->as_hashref->{title} }
36 0     0 1 0 sub ttl { shift->as_hashref->{ttl} }
37 3     3 1 1538 sub type { shift->as_hashref->{type} }
38 0     0 1 0 sub value { shift->as_hashref->{value} }
39 0     0 1 0 sub weight { shift->as_hashref->{weight} }
40              
41             sub delete {
42 1     1 1 899 my ($self) = @_;
43 1         24 $self->request('DELETE', $self->path . $self->id);
44             }
45              
46             sub update {
47 0     0 1   my ($self, %data) = @_;
48              
49 0           my %req;
50 0           for my $old (keys %data) {
51 0           my $new = lower_camel_case($old);
52 0           $req{$new} = $data{$old};
53             }
54              
55 0   0       $req{id} //= $self->id;
56 0   0       $req{name} //= $self->name;
57              
58 0           my $id = $self->id;
59 0           my $type = $self->type;
60 0           my $name = $self->name;
61 0           $self->clear_as_hashref;
62 0           $self->request(PUT => $self->path . $id, \%req);
63              
64             # GRR DME doesn't return the updasted record and there is no way to get a
65             # single record by id
66 0 0         $name = $req{name} if $req{name};
67 0           my @records = $self->domain->records(type => $type, name => $name);
68 0           for my $record (@records) {
69 0 0         next unless $record->id eq $id;
70 0           $self->as_hashref($record->as_hashref);
71             }
72             }
73              
74 0     0 0   sub monitor_path { 'monitor/' . shift->id }
75              
76             sub get_monitor {
77 0     0 1   my ($self) = @_;
78 0           return WWW::DNSMadeEasy::Monitor->new(
79             response => $self->request(GET => $self->monitor_path),
80             dme => $self->dme,
81             record => $self,
82             );
83             }
84              
85             sub create_monitor {
86 0     0 0   my ($self, %data) = @_;
87              
88 0           my %req;
89 0           for my $old (keys %data) {
90 0           my $new = lower_camel_case($old);
91 0           $req{$new} = $data{$old};
92             }
93              
94 0           my $monitor = WWW::DNSMadeEasy::Monitor->new(
95             response => $self->request(PUT => $self->monitor_path, \%req),
96             dme => $self->dme,
97             record => $self,
98             );
99             }
100              
101             1;
102              
103             __END__
104              
105             =pod
106              
107             =encoding UTF-8
108              
109             =head1 NAME
110              
111             WWW::DNSMadeEasy::ManagedDomain::Record - A managed domain record in the DNSMadeEasy API
112              
113             =head1 VERSION
114              
115             version 0.100
116              
117             =head1 METHODS
118              
119             =head2 delete()
120              
121             =head2 update(%data)
122              
123             Can't update id, name, type, or gtd_location.
124              
125             =head2 response()
126              
127             Returns this object as a hashreference.
128              
129             =head2 get_monitor()
130              
131             Returns a L<WWW::DNSMadeEasy::Monitor> object which deals with dns failover and system monitoring.
132              
133             =head2 description
134              
135             =head2 dynamic_dns
136              
137             =head2 failed
138              
139             =head2 failover
140              
141             =head2 gtd_location
142              
143             =head2 hard_link
144              
145             =head2 id
146              
147             =head2 keywords
148              
149             =head2 monitor
150              
151             =head2 mxLevel
152              
153             =head2 name
154              
155             =head2 password
156              
157             =head2 port
158              
159             =head2 priority
160              
161             =head2 redirect_type
162              
163             =head2 source
164              
165             =head2 source_id
166              
167             =head2 title
168              
169             =head2 ttl
170              
171             =head2 type
172              
173             =head2 value
174              
175             =head2 weight
176              
177             =head1 METHODS
178              
179             =head1 RECORD ATTRIBUTES
180              
181             =head1 SUPPORT
182              
183             IRC
184              
185             Join #duckduckgo on irc.freenode.net and highlight Getty or /msg me.
186              
187             Repository
188              
189             http://github.com/Getty/p5-www-dnsmadeeasy
190             Pull request and additional contributors are welcome
191              
192             Issue Tracker
193              
194             http://github.com/Getty/p5-www-dnsmadeeasy/issues
195              
196             =for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
197              
198             =head1 SUPPORT
199              
200             =head2 Source Code
201              
202             The code is open to the world, and available for you to hack on. Please feel free to browse it and play
203             with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
204             from your repository :)
205              
206             L<https://github.com/Getty/p5-www-dnsmadeeasy>
207              
208             git clone https://github.com/Getty/p5-www-dnsmadeeasy.git
209              
210             =head1 AUTHOR
211              
212             Torsten Raudssus <torsten@raudssus.de>
213              
214             =head1 COPYRIGHT AND LICENSE
215              
216             This software is copyright (c) 2012 by L<Torsten Raudssus|https://raudssus.de/>.
217              
218             This is free software; you can redistribute it and/or modify it under
219             the same terms as the Perl 5 programming language system itself.
220              
221             =cut