File Coverage

blib/lib/Net/EPP/Frame/Command/Update/Domain.pm
Criterion Covered Total %
statement 15 145 10.3
branch 0 16 0.0
condition 0 6 0.0
subroutine 5 22 22.7
pod 1 15 6.6
total 21 204 10.2


line stmt bran cond sub pod time code
1             package Net::EPP::Frame::Command::Update::Domain;
2 1     1   9 use List::Util qw(any);
  1         2  
  1         154  
3 1     1   9 use base qw(Net::EPP::Frame::Command::Update);
  1         2  
  1         132  
4 1     1   7 use Net::EPP::Frame::ObjectSpec;
  1         2  
  1         27  
5 1     1   5 use strict;
  1         3  
  1         39  
6 1     1   6 use warnings;
  1         2  
  1         2223  
7              
8             our $DNSSEC_URN = 'urn:ietf:params:xml:ns:secDNS-1.1';
9              
10             =pod
11              
12             =head1 NAME
13              
14             Net::EPP::Frame::Command::Update::Domain - an instance of L
15             for domain names.
16              
17             =head1 SYNOPSIS
18              
19             use Net::EPP::Frame::Command::Update::Domain;
20             use strict;
21              
22             my $info = Net::EPP::Frame::Command::Update::Domain->new;
23             $info->setDomain('example.tld');
24              
25             print $info->toString(1);
26              
27             This results in an XML document like this:
28              
29            
30            
31             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
32             xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0
33             epp-1.0.xsd">
34            
35            
36            
37             xmlns:domain="urn:ietf:params:xml:ns:domain-1.0"
38             xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0
39             domain-1.0.xsd">
40             example-1.tldE/domain:name>
41            
42            
43             0cf1b8f7e14547d26f03b7641660c641d9e79f45
44            
45            
46              
47             =head1 OBJECT HIERARCHY
48              
49             L
50             +----L
51             +----L
52             +----L
53             +----L
54             +----L
55              
56             =cut
57              
58             sub new {
59 0     0 1   my $package = shift;
60 0           my $self = bless($package->SUPER::new('update'), $package);
61              
62 0           my $domain = $self->addObject(Net::EPP::Frame::ObjectSpec->spec('domain'));
63              
64 0           foreach my $grp (qw(add rem chg)) {
65 0           my $el = $self->createElement(sprintf('domain:%s', $grp));
66 0           $self->getNode('update')->getChildNodes->shift->appendChild($el);
67             }
68              
69 0           return $self;
70             }
71              
72             =pod
73              
74             =head1 METHODS
75              
76             $frame->setDomain($domain_name);
77              
78             This specifies the domain name to be updated.
79              
80             =cut
81              
82             sub setDomain {
83 0     0 0   my ($self, $domain) = @_;
84              
85 0           my $name = $self->createElement('domain:name');
86 0           $name->appendText($domain);
87              
88 0           my $n = $self->getNode('update')->getChildNodes->shift;
89 0           $n->insertBefore($name, $n->firstChild);
90              
91 0           return 1;
92             }
93              
94             =pod
95              
96             $frame->addStatus($type, $info);
97              
98             Add a status of $type with the optional extra $info.
99              
100             =cut
101              
102             sub addStatus {
103 0     0 0   my ($self, $type, $info) = @_;
104 0           my $status = $self->createElement('domain:status');
105 0           $status->setAttribute('s', $type);
106 0           $status->setAttribute('lang', 'en');
107 0 0         if ($info) {
108 0           $status->appendText($info);
109             }
110 0           $self->getElementsByLocalName('domain:add')->shift->appendChild($status);
111 0           return 1;
112             }
113              
114             =pod
115              
116             $frame->remStatus($type);
117              
118             Remove a status of $type.
119              
120             =cut
121              
122             sub remStatus {
123 0     0 0   my ($self, $type) = @_;
124 0           my $status = $self->createElement('domain:status');
125 0           $status->setAttribute('s', $type);
126 0           $self->getElementsByLocalName('domain:rem')->shift->appendChild($status);
127 0           return 1;
128             }
129              
130             =pod
131              
132             $frame->addContact($type, $contact);
133            
134             Add a contact of $type.
135              
136             =cut
137              
138             sub addContact {
139 0     0 0   my ($self, $type, $contact_id) = @_;
140              
141 0           my $contact = $self->createElement('domain:contact');
142 0           $contact->setAttribute('type', $type);
143 0           $contact->appendText($contact_id);
144              
145 0           $self->getElementsByLocalName('domain:add')->shift->appendChild($contact);
146 0           return 1;
147             }
148              
149             =pod
150            
151             $frame->remContact($type, $contact);
152            
153             Remove a contact of $type.
154              
155             =cut
156              
157             sub remContact {
158 0     0 0   my ($self, $type, $contact_id) = @_;
159              
160 0           my $contact = $self->createElement('domain:contact');
161 0           $contact->setAttribute('type', $type);
162 0           $contact->appendText($contact_id);
163              
164 0           $self->getElementsByLocalName('domain:rem')->shift->appendChild($contact);
165 0           return 1;
166             }
167              
168             =pod
169              
170             $frame->chgAuthinfo($auth);
171              
172             Change the authinfo.
173              
174             =cut
175              
176             sub chgAuthInfo {
177 0     0 0   my ($self, $authInfo) = @_;
178              
179 0           my $el = $self->createElement('domain:authInfo');
180 0           my $pw = $self->createElement('domain:pw');
181 0           $pw->appendText($authInfo);
182 0           $el->appendChild($pw);
183              
184 0           $self->getElementsByLocalName('domain:chg')->shift->appendChild($el);
185 0           return 1;
186             }
187              
188             =pod
189              
190             $frame->chgRegistrant($registrant);
191              
192             Change the authinfo.
193              
194             =cut
195              
196             sub chgRegistrant {
197 0     0 0   my ($self, $contact) = @_;
198              
199 0           my $registrant = $self->createElement('domain:registrant');
200 0           $registrant->appendText($contact);
201              
202 0           $self->getElementsByLocalName('domain:chg')->shift->appendChild($registrant);
203 0           return 1;
204             }
205              
206             =pod
207              
208             $frame->addNS('ns0.example.com'); # host object mode
209              
210             $frame->addNS({'name' => 'ns0.example.com', 'addrs' => [ { 'addr' => '127.0.0.1', 'type' => 4 } ] }); # host attribute mode
211              
212             =cut
213              
214             sub addNS {
215 0     0 0   my ($self, @ns) = @_;
216              
217 0 0         if (ref $ns[0] eq 'HASH') {
218 0           $self->addHostAttrNS(@ns);
219             } else {
220 0           $self->addHostObjNS(@ns);
221             }
222 0           return 1;
223             }
224              
225             sub addHostAttrNS {
226 0     0 0   my ($self, @ns) = @_;
227              
228 0           my $ns = $self->createElement('domain:ns');
229              
230             # Adding attributes
231 0           foreach my $host (@ns) {
232 0           my $hostAttr = $self->createElement('domain:hostAttr');
233              
234             # Adding NS name
235 0           my $hostName = $self->createElement('domain:hostName');
236 0           $hostName->appendText($host->{name});
237 0           $hostAttr->appendChild($hostName);
238              
239             # Adding IP addresses
240 0 0 0       if (exists $host->{addrs} && ref $host->{addrs} eq 'ARRAY') {
241 0           foreach my $addr (@{$host->{addrs}}) {
  0            
242 0           my $hostAddr = $self->createElement('domain:hostAddr');
243 0           $hostAddr->appendText($addr->{addr});
244 0           $hostAddr->setAttribute(ip => $addr->{version});
245 0           $hostAttr->appendChild($hostAddr);
246             }
247             }
248              
249             # Adding host info to frame
250 0           $ns->appendChild($hostAttr);
251             }
252              
253 0           $self->getElementsByLocalName('domain:add')->shift->appendChild($ns);
254 0           return 1;
255             }
256              
257             sub addHostObjNS {
258 0     0 0   my ($self, @ns) = @_;
259              
260 0           my $ns = $self->createElement('domain:ns');
261 0           foreach my $host (@ns) {
262 0           my $el = $self->createElement('domain:hostObj');
263 0           $el->appendText($host);
264 0           $ns->appendChild($el);
265             }
266              
267 0           $self->getElementsByLocalName('domain:add')->shift->appendChild($ns);
268 0           return 1;
269             }
270              
271             =pod
272              
273             $frame->remNS('ns0.example.com'); # host object mode
274              
275             $frame->remNS({'name' => 'ns0.example.com', 'addrs' => [ { 'addr' => '127.0.0.1', 'type' => 4 } ] }); # host attribute mode
276              
277             =cut
278              
279             sub remNS {
280 0     0 0   my ($self, @ns) = @_;
281              
282 0 0         if (ref $ns[0] eq 'HASH') {
283 0           $self->remHostAttrNS(@ns);
284             } else {
285 0           $self->remHostObjNS(@ns);
286             }
287 0           return 1;
288             }
289              
290             sub remHostAttrNS {
291 0     0 0   my ($self, @ns) = @_;
292              
293 0           my $ns = $self->createElement('domain:ns');
294              
295             # Adding attributes
296 0           foreach my $host (@ns) {
297 0           my $hostAttr = $self->createElement('domain:hostAttr');
298              
299             # Adding NS name
300 0           my $hostName = $self->createElement('domain:hostName');
301 0           $hostName->appendText($host->{name});
302 0           $hostAttr->appendChild($hostName);
303              
304             # Adding IP addresses
305 0 0 0       if (exists $host->{addrs} && ref $host->{addrs} eq 'ARRAY') {
306 0           foreach my $addr (@{$host->{addrs}}) {
  0            
307 0           my $hostAddr = $self->createElement('domain:hostAddr');
308 0           $hostAddr->appendText($addr->{addr});
309 0           $hostAddr->setAttribute(ip => $addr->{version});
310 0           $hostAttr->appendChild($hostAddr);
311             }
312             }
313              
314             # Adding host info to frame
315 0           $ns->appendChild($hostAttr);
316             }
317              
318 0           $self->getElementsByLocalName('domain:rem')->shift->appendChild($ns);
319 0           return 1;
320             }
321              
322             sub remHostObjNS {
323 0     0 0   my ($self, @ns) = @_;
324              
325 0           my $ns = $self->createElement('domain:ns');
326 0           foreach my $host (@ns) {
327 0           my $el = $self->createElement('domain:hostObj');
328 0           $el->appendText($host);
329 0           $ns->appendChild($el);
330             }
331              
332 0           $self->getElementsByLocalName('domain:rem')->shift->appendChild($ns);
333 0           return 1;
334             }
335              
336             =pod
337              
338             =head2 DNSSEC methods
339              
340             =cut
341              
342             sub _get_dnsssec {
343 0     0     my $self = shift;
344 0           my $tag = shift;
345              
346 0           my $el = self->getElementsByTagNameNS($DNSSEC_URN, $tag);
347 0 0         return $el if $el;
348              
349 0           my $ext = $self->getNode('extension');
350 0 0         $ext = $self->getNode('command')->addNewChild(undef, 'extension')
351             if not defined $ext;
352              
353 0           my $upd = $ext->addNewChild($DNSSEC_URN, 'secDNS:update');
354 0           $upd->addNewChild($DNSSEC_URN, 'secDNS:add');
355 0           $upd->addNewChild($DNSSEC_URN, 'secDNS:rem');
356              
357 0           return $self->_get_dnssec($tag);
358             }
359              
360             =pod
361              
362             =head2 TTL Extension
363              
364             $frame->chgTTLs({
365             NS => 3600,
366             DS => 900,
367             });
368              
369             Specify TTLs for DNS records above the zone cut. The server must support the
370             TTL extension.
371              
372             =cut
373              
374             sub chgTTLs {
375 0     0 0   my ($self, $ttls) = @_;
376              
377 0           foreach my $type (keys(%{$ttls})) {
  0            
378 0           my $ttl = $self->createExtensionElementFor(Net::EPP::Frame::ObjectSpec->xmlns('ttl'))->appendChild($self->createElement('ttl'));
379 0           $ttl->appendText($ttls->{$type});
380 0 0   0     if (any { $type eq $_ } qw(NS DS DNAME A AAAA)) {
  0            
381 0           $ttl->setAttribute('for', $type);
382              
383             } else {
384 0           $ttl->setAttribute('for', 'custom');
385 0           $ttl->setAttribute('custom', $type);
386              
387             }
388             }
389             }
390              
391             1;