EPP/Frame/Command/Update/Domain.pm

filter: Statementstmt 11.5% 17 / 147 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 22.7% 5 / 22 Podpod 6.6% 1 / 15 totaltotal 10.9% 23 / 210 CC 19 SCAR 24.5
CC
19
Cov
10%
addHostAttrNS
30.0
remHostAttrNS
30.0
_get_dnsssec
12.0
CRAP 11.6
« EPP/Client.pm ↑ Summary EPP/Frame/Command/Create/Contact.pm »
1 package Net::EPP::Frame::Command::Update::Domain;
2 1 ▶use List::Util qw(any);
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use base qw(Net::EPP::Frame::Command::Update);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Net::EPP::Frame::ObjectSpec;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 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<Net::EPP::Frame::Command::Update>
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 <?xml version="1.0" encoding="UTF-8"?>
30 <epp xmlns="urn:ietf:params:xml:ns:epp-1.0"
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 <command>
35 <update>
36 <domain:update
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 <domain:name>example-1.tldE<lt>/domain:name>
41 </domain:update>
42 </update>
43 <clTRID>0cf1b8f7e14547d26f03b7641660c641d9e79f45</clTRIDE<gt>
44 </command>
45 </epp>
46  
47 =head1 OBJECT HIERARCHY
48  
49 L<XML::LibXML::Node>
50 +----L<XML::LibXML::Document>
51 +----L<Net::EPP::Frame>
52 +----L<Net::EPP::Frame::Command>
53 +----L<Net::EPP::Frame::Command::Update>
54 +----L<Net::EPP::Frame::Command::Update::Domain>
55  
56 =cut
57  
58 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
59 0 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 0 ▶sub setDomain {
Subroutine setDomain: not called CC=1 SCAR=6.9
Pod undocumented
83 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 0 ▶sub addStatus {
Subroutine addStatus: not called CC=2 SCAR=17.9
Pod undocumented
103 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 ▶ if ($info) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info) 0 0 0
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 0 ▶sub remStatus {
Subroutine remStatus: not called CC=1 SCAR=6.9
Pod undocumented
123 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 0 ▶sub addContact {
Subroutine addContact: not called CC=1 SCAR=6.9
Pod undocumented
139 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 0 ▶sub remContact {
Subroutine remContact: not called CC=1 SCAR=6.9
Pod undocumented
158 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 0 ▶sub chgAuthInfo {
Subroutine chgAuthInfo: not called CC=1 SCAR=6.9
Pod undocumented
177 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 0 ▶sub chgRegistrant {
Subroutine chgRegistrant: not called CC=1 SCAR=6.9
Pod undocumented
197 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 0 ▶sub addNS {
Subroutine addNS: not called CC=2 SCAR=17.9
Pod undocumented
215 0 my ($self, @ns) = @_;
216  
217 0 ▶ if (ref $ns[0] eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ns[0] eq 'HASH') { } 0 0 0
218 0 $self->addHostAttrNS(@ns);
219 } else {
220 0 $self->addHostObjNS(@ns);
221 }
222 0 return 1;
223 }
224  
225 0 ▶sub addHostAttrNS {
Subroutine addHostAttrNS: not called CC=5 SCAR=34.0
Pod undocumented
226 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 ▶ if (exists $host->{addrs} && ref $host->{addrs} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $host->{"addrs"} and ref $host->{"addrs"} eq "ARRAY") 0 0 0
Condition0%0/3
exists $host->{"addrs"} and ref $host->{"addrs"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $host->{"addrs"} and ref $host->{"addrs"} eq "ARRAY"
exists $host->{"addrs"} ref $host->{"addrs"} eq "ARRAY"
Truth table0%0/3
A and B
A= exists $host->{"addrs"}B= ref $host->{"addrs"} eq "ARRAY"
ABresult
0X0
100
111
241 0 foreach my $addr (@{$host->{addrs}}) {
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 0 ▶sub addHostObjNS {
Subroutine addHostObjNS: not called CC=2 SCAR=17.9
Pod undocumented
258 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 0 ▶sub remNS {
Subroutine remNS: not called CC=2 SCAR=17.9
Pod undocumented
280 0 my ($self, @ns) = @_;
281  
282 0 ▶ if (ref $ns[0] eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ns[0] eq 'HASH') { } 0 0 0
283 0 $self->remHostAttrNS(@ns);
284 } else {
285 0 $self->remHostObjNS(@ns);
286 }
287 0 return 1;
288 }
289  
290 0 ▶sub remHostAttrNS {
Subroutine remHostAttrNS: not called CC=5 SCAR=34.0
Pod undocumented
291 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 ▶ if (exists $host->{addrs} && ref $host->{addrs} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $host->{"addrs"} and ref $host->{"addrs"} eq "ARRAY") 0 0 0
Condition0%0/3
exists $host->{"addrs"} and ref $host->{"addrs"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $host->{"addrs"} and ref $host->{"addrs"} eq "ARRAY"
exists $host->{"addrs"} ref $host->{"addrs"} eq "ARRAY"
Truth table0%0/3
A and B
A= exists $host->{"addrs"}B= ref $host->{"addrs"} eq "ARRAY"
ABresult
0X0
100
111
306 0 foreach my $addr (@{$host->{addrs}}) {
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 0 ▶sub remHostObjNS {
Subroutine remHostObjNS: not called CC=2 SCAR=17.9
Pod undocumented
323 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 0 ▶sub _get_dnsssec {
Subroutine _get_dnsssec: not called CC=3 SCAR=24.8
343 0 my $self = shift;
344 0 my $tag = shift;
345  
346 0 my $el = self->getElementsByTagNameNS($DNSSEC_URN, $tag);
347 0 ▶ return $el if $el;
Branch: 1 branch
BranchTrueFalseTotal
if $el 0 0 0
348  
349 0 my $ext = $self->getNode('extension');
350 0 ▶ $ext = $self->getNode('command')->addNewChild(undef, 'extension')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ext 0 0 0
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 0 ▶sub chgTTLs {
Subroutine chgTTLs: not called CC=3 SCAR=24.8
Pod undocumented
375 0 my ($self, $ttls) = @_;
376  
377 0 foreach my $type (keys(%{$ttls})) {
378 0 my $ttl = $self->createExtensionElementFor(Net::EPP::Frame::ObjectSpec->xmlns('ttl'))->appendChild($self->createElement('ttl'));
379 0 $ttl->appendText($ttls->{$type});
380 0 ▶ if (any { $type eq $_ } qw(NS DS DNAME A AAAA)) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $type eq $_; } , 'NS', 'DS', 'DNAME', 'A', 'AAAA')) { } 0 0 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 1;
« EPP/Client.pm ↑ Summary EPP/Frame/Command/Create/Contact.pm »