EPP/Frame/Command/Create/Domain.pm

filter: Statementstmt 13.5% 13 / 96 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 23.5% 4 / 17 Podpod 8.3% 1 / 12 totaltotal 12.4% 18 / 145 CC 13 SCAR 22.9
CC
13
Cov
12%
addHostAttrNS
30.0
setPeriod
12.0
setTTLs
12.0
CRAP 9.9
« EPP/Frame/Command/Update/Contact.pm ↑ Summary EPP/Frame/Command/Update.pm »
1 package Net::EPP::Frame::Command::Create::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::Create);
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  
7 =pod
8  
9 =head1 NAME
10  
11 Net::EPP::Frame::Command::Create::Domain - an instance of L<Net::EPP::Frame::Command::Create>
12 for domain objects.
13  
14 =head1 SYNOPSIS
15  
16 use Net::EPP::Frame::Command::Create::Domain;
17 use strict;
18  
19 my $create = Net::EPP::Frame::Command::Create::Domain->new;
20 $create->setDomain('example.uk.com);
21  
22 print $create->toString(1);
23  
24 This results in an XML document like this:
25  
26 <?xml version="1.0" encoding="UTF-8"?>
27 <epp xmlns="urn:ietf:params:xml:ns:epp-1.0"
28 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
29 xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0
30 epp-1.0.xsd">
31 <command>
32 <check>
33 <domain:create
34 xmlns:contact="urn:ietf:params:xml:ns:contact-1.0"
35 xsi:schemaLocation="urn:ietf:params:xml:ns:contact-1.0
36 contact-1.0.xsd">
37 <domain:name>example-1.tldE<lt>/domain:name>
38 </domain:create>
39 </check>
40 <clTRID>0cf1b8f7e14547d26f03b7641660c641d9e79f45</clTRIDE<gt>
41 </command>
42 </epp>
43  
44 =head1 OBJECT HIERARCHY
45  
46 L<XML::LibXML::Node>
47 +----L<XML::LibXML::Document>
48 +----L<Net::EPP::Frame>
49 +----L<Net::EPP::Frame::Command>
50 +----L<Net::EPP::Frame::Command::Create>
51 +----L<Net::EPP::Frame::Command::Create::Domain>
52  
53 =cut
54  
55 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
56 0 my $package = shift;
57 0 my $self = bless($package->SUPER::new('create'), $package);
58  
59 0 $self->addObject(Net::EPP::Frame::ObjectSpec->spec('domain'));
60  
61 0 return $self;
62 }
63  
64 =pod
65  
66 =head1 METHODS
67  
68 my $element = $frame->setDomain($domain_name);
69  
70 This sets the name of the object to be created. Returns the
71 C<E<lt>domain:nameE<gt>> element.
72  
73 =cut
74  
75 0 ▶sub setDomain {
Subroutine setDomain: not called CC=1 SCAR=6.9
Pod undocumented
76 0 my ($self, $domain) = @_;
77  
78 0 my $name = $self->createElement('domain:name');
79 0 $name->appendText($domain);
80  
81 0 $self->getNode('create')->getChildNodes->shift->appendChild($name);
82  
83 0 return 1;
84 }
85  
86 =pod
87  
88 =head1
89  
90 $frame->setPeriod(1, 'y');
91  
92 Set the initial registration period. The second argument is optional.
93  
94 =cut
95  
96 0 ▶sub setPeriod {
Subroutine setPeriod: not called CC=3 SCAR=24.8
Pod undocumented
97 0 my ($self, $period, $unit) = @_;
98  
99 0 ▶ $unit = 'y' if (!defined($unit) || $unit eq '');
Branch: 1 branch
BranchTrueFalseTotal
if not defined $unit or $unit eq "" 0 0 0
Condition0%0/3
not defined $unit or $unit eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $unit or $unit eq ""
not defined $unit $unit eq ""
Truth table0%0/3
not(A) or B
A= not defined $unitB= $unit eq ""
ABresult
1X1
011
000
100  
101 0 my $el = $self->createElement('domain:period');
102 0 $el->setAttribute('unit', $unit);
103 0 $el->appendText(int($period));
104  
105 0 $self->getNode('create')->getChildNodes->shift->appendChild($el);
106  
107 0 return 1;
108 }
109  
110 =pod
111  
112 =head1
113  
114 $frame->setRegistrant($id);
115  
116 Set the registrant.
117  
118 =cut
119  
120 0 ▶sub setRegistrant {
Subroutine setRegistrant: not called CC=1 SCAR=6.9
Pod undocumented
121 0 my ($self, $contact) = @_;
122  
123 0 my $registrant = $self->createElement('domain:registrant');
124 0 $registrant->appendText($contact);
125  
126 0 $self->getNode('create')->getChildNodes->shift->appendChild($registrant);
127  
128 0 return 1;
129 }
130  
131 =pod
132  
133 =head1
134  
135 $frame->setContacts({
136 'admin' => 'H12345',
137 'tech' => 'H54321',
138 'billing' => 'H23451',
139 }));
140  
141 Set the contacts.
142  
143 =cut
144  
145 0 ▶sub setContacts {
Subroutine setContacts: not called CC=2 SCAR=17.9
Pod undocumented
146 0 my ($self, $contacts) = @_;
147 0 my $parent = $self->getNode('create')->getChildNodes->shift;
148  
149 0 foreach my $type (keys(%{$contacts})) {
150 0 my $contact = $self->createElement('domain:contact');
151 0 $contact->setAttribute('type', $type);
152 0 $contact->appendText($contacts->{$type});
153  
154 0 $parent->appendChild($contact);
155 }
156  
157 0 return 1;
158 }
159  
160 #
161 # Type of elements of @ns depends on NS model used by EPP server.
162 # hostObj model:
163 # each element is a name of NS host object
164 # hostAttr model:
165 # each element is a hashref:
166 # {
167 # name => 'ns1.example.com,
168 # addrs => [
169 # { version => 'v4', addr => '192.168.0.10', },
170 # { version => 'v4', addr => '192.168.0.20', },
171 # ...
172 # ];
173 # }
174 #
175 0 ▶sub setNS {
Subroutine setNS: not called CC=2 SCAR=17.9
Pod undocumented
176 0 my ($self, @ns) = @_;
177  
178 0 ▶ if (ref $ns[0] eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ns[0] eq 'HASH') { } 0 0 0
179 0 $self->addHostAttrNS(@ns);
180 } else {
181 0 $self->addHostObjNS(@ns);
182 }
183  
184 0 return 1;
185 }
186  
187 0 ▶sub addHostAttrNS {
Subroutine addHostAttrNS: not called CC=5 SCAR=34.0
Pod undocumented
188 0 my ($self, @ns) = @_;
189  
190 0 my $ns = $self->createElement('domain:ns');
191  
192 # Adding attributes
193 0 foreach my $host (@ns) {
194 0 my $hostAttr = $self->createElement('domain:hostAttr');
195  
196 # Adding NS name
197 0 my $hostName = $self->createElement('domain:hostName');
198 0 $hostName->appendText($host->{name});
199 0 $hostAttr->appendChild($hostName);
200  
201 # Adding IP addresses
202 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
203 0 foreach my $addr (@{$host->{addrs}}) {
204 0 my $hostAddr = $self->createElement('domain:hostAddr');
205 0 $hostAddr->appendText($addr->{addr});
206 0 $hostAddr->setAttribute(ip => $addr->{version});
207 0 $hostAttr->appendChild($hostAddr);
208 }
209 }
210  
211 # Adding host info to frame
212 0 $ns->appendChild($hostAttr);
213 }
214 0 $self->getNode('create')->getChildNodes->shift->appendChild($ns);
215 0 return 1;
216 }
217  
218 0 ▶sub addHostObjNS {
Subroutine addHostObjNS: not called CC=2 SCAR=17.9
Pod undocumented
219 0 my ($self, @ns) = @_;
220  
221 0 my $ns = $self->createElement('domain:ns');
222 0 foreach my $host (@ns) {
223 0 my $el = $self->createElement('domain:hostObj');
224 0 $el->appendText($host);
225 0 $ns->appendChild($el);
226 }
227 0 $self->getNode('create')->getChildNodes->shift->appendChild($ns);
228 0 return 1;
229 }
230  
231 0 ▶sub setAuthInfo {
Subroutine setAuthInfo: not called CC=1 SCAR=6.9
Pod undocumented
232 0 my ($self, $authInfo) = @_;
233 0 my $el = $self->addEl('authInfo');
234 0 my $pw = $self->createElement('domain:pw');
235 0 $pw->appendText($authInfo);
236 0 $el->appendChild($pw);
237 0 return $el;
238 }
239  
240 0 ▶sub appendStatus {
Subroutine appendStatus: not called CC=1 SCAR=6.9
Pod undocumented
241 0 my ($self, $status) = @_;
242 0 return $self->addEl('status', $status);
243 }
244  
245 0 ▶sub addEl {
Subroutine addEl: not called CC=2 SCAR=17.9
Pod undocumented
246 0 my ($self, $name, $value) = @_;
247  
248 0 my $el = $self->createElement('domain:' . $name);
249 0 ▶ $el->appendText($value) if defined($value);
Branch: 1 branch
BranchTrueFalseTotal
if defined $value 0 0 0
250  
251 0 $self->getNode('create')->getChildNodes->shift->appendChild($el);
252  
253 0 return $el;
254  
255 }
256  
257 =pod
258  
259 =head2 TTL Extension
260  
261 $frame->setTTLs({
262 NS => 3600,
263 DS => 900,
264 });
265  
266 Specify TTLs for DNS records above the zone cut. The server must support the
267 TTL extension.
268  
269 =cut
270  
271 0 ▶sub setTTLs {
Subroutine setTTLs: not called CC=3 SCAR=24.8
Pod undocumented
272 0 my ($self, $ttls) = @_;
273  
274 0 foreach my $type (keys(%{$ttls})) {
275 0 my $ttl = $self->createExtensionElementFor(Net::EPP::Frame::ObjectSpec->xmlns('ttl'))->appendChild($self->createElement('ttl'));
276 0 $ttl->appendText($ttls->{$type});
277 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
278 0 $ttl->setAttribute('for', $type);
279  
280 } else {
281 0 $ttl->setAttribute('for', 'custom');
282 0 $ttl->setAttribute('custom', $type);
283  
284 }
285 }
286 }
287  
288 1 1;
« EPP/Frame/Command/Update/Contact.pm ↑ Summary EPP/Frame/Command/Update.pm »