EPP/Frame/Command/Update/Host.pm

filter: Statementstmt 17.5% 13 / 74 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 28.5% 4 / 14 Podpod 11.1% 1 / 9 totaltotal 17.4% 18 / 103 CC 8 SCAR 16.4
CC
8
Cov
16%
chgTTLs
12.0
new
6.0
addStatus
6.0
CRAP 5.1
« EPP/Frame/Command/Update.pm ↑ Summary EPP/Frame/Command/Create/Host.pm »
1 package Net::EPP::Frame::Command::Update::Host;
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  
7 =pod
8  
9 =head1 NAME
10  
11 Net::EPP::Frame::Command::Update::Host - an instance of L<Net::EPP::Frame::Command::Update>
12 for host objects.
13  
14 =head1 SYNOPSIS
15  
16 use Net::EPP::Frame::Command::Update::Host;
17 use strict;
18  
19 my $info = Net::EPP::Frame::Command::Update::Host->new;
20 $info->setHost('ns0.example.tld');
21  
22 print $info->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 <info>
33 <host:update
34 xmlns:host="urn:ietf:params:xml:ns:host-1.0"
35 xsi:schemaLocation="urn:ietf:params:xml:ns:host-1.0
36 host-1.0.xsd">
37 <host:name>example-1.tldE<lt>/host:name>
38 </host:update>
39 </info>
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::Update>
51 +----L<Net::EPP::Frame::Command::Update::Host>
52  
53 =cut
54  
55 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
56 0 my $package = shift;
57 0 my $self = bless($package->SUPER::new('update'), $package);
58  
59 0 my $host = $self->addObject(Net::EPP::Frame::ObjectSpec->spec('host'));
60  
61 # 'chg' element's contents are not optional for hosts, so we'll add
62 # this element only when we plan to use it (accessor is overriden)
63 0 foreach my $grp (qw(add rem)) {
64 0 my $el = $self->createElement(sprintf('host:%s', $grp));
65 0 $self->getNode('update')->getChildNodes->shift->appendChild($el);
66 }
67  
68 0 return $self;
69 }
70  
71 =pod
72  
73 =head1 METHODS
74  
75 $frame->setHost($host_name);
76  
77 This specifies the host object to be updated.
78  
79 =cut
80  
81 0 ▶sub setHost {
Subroutine setHost: not called CC=1 SCAR=6.9
Pod undocumented
82 0 my ($self, $host) = @_;
83  
84 0 my $name = $self->createElement('host:name');
85 0 $name->appendText($host);
86  
87 0 my $n = $self->getNode('update')->getChildNodes->shift;
88 0 $n->insertBefore($name, $n->firstChild);
89  
90 0 return 1;
91 }
92  
93 =pod
94  
95 $frame->addStatus($type, $info);
96  
97 Add a status of $type with the optional extra $info.
98  
99 =cut
100  
101 0 ▶sub addStatus {
Subroutine addStatus: not called CC=2 SCAR=17.9
Pod undocumented
102 0 my ($self, $type, $info) = @_;
103 0 my $status = $self->createElement('host:status');
104 0 $status->setAttribute('s', $type);
105 0 $status->setAttribute('lang', 'en');
106 0 ▶ if ($info) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info) 0 0 0
107 0 $status->appendText($info);
108 }
109 0 $self->getElementsByLocalName('host:add')->shift->appendChild($status);
110 0 return 1;
111 }
112  
113 =pod
114  
115 $frame->remStatus($type);
116  
117 Remove a status of $type.
118  
119 =cut
120  
121 0 ▶sub remStatus {
Subroutine remStatus: not called CC=1 SCAR=6.9
Pod undocumented
122 0 my ($self, $type) = @_;
123 0 my $status = $self->createElement('host:status');
124 0 $status->setAttribute('s', $type);
125 0 $self->getElementsByLocalName('host:rem')->shift->appendChild($status);
126 0 return 1;
127 }
128  
129 =pod
130  
131 $frame->addAddr({ 'ip' => '10.0.0.1', 'version' => 'v4' });
132  
133 Add a set of IP addresses to the host object. EPP supports multiple
134 addresses of different versions.
135  
136 =cut
137  
138 0 ▶sub addAddr {
Subroutine addAddr: not called CC=2 SCAR=17.9
Pod undocumented
139 0 my ($self, @addr) = @_;
140  
141 0 foreach my $ip (@addr) {
142 0 my $el = $self->createElement('host:addr');
143 0 $el->appendText($ip->{ip});
144 0 $el->setAttribute('ip', $ip->{version});
145 0 $self->getElementsByLocalName('host:add')->shift->appendChild($el);
146 }
147 0 return 1;
148 }
149  
150 =pod
151  
152 $frame->remAddr({ 'ip' => '10.0.0.2', 'version' => 'v4' });
153  
154 Remove a set of IP addresses from the host object. EPP supports multiple
155 addresses of different versions.
156  
157 =cut
158  
159 0 ▶sub remAddr {
Subroutine remAddr: not called CC=2 SCAR=17.9
Pod undocumented
160 0 my ($self, @addr) = @_;
161  
162 0 foreach my $ip (@addr) {
163 0 my $el = $self->createElement('host:addr');
164 0 $el->appendText($ip->{ip});
165 0 $el->setAttribute('ip', $ip->{version});
166 0 $self->getElementsByLocalName('host:rem')->shift->appendChild($el);
167 }
168 0 return 1;
169 }
170  
171 =pod
172 my $el = $frame->chg;
173  
174 Lazy-building of 'host:chg'element.
175  
176 =cut
177  
178 0 ▶sub chg {
Subroutine chg: not called CC=2 SCAR=17.9
Pod undocumented
179 0 my $self = shift;
180  
181 0 my $chg = $self->getElementsByLocalName('host:chg')->shift;
182 0 ▶ if ($chg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chg) { } 0 0 0
183 0 return $chg;
184 } else {
185 0 my $el = $self->createElement('host:chg');
186 0 $self->getNode('update')->getChildNodes->shift->appendChild($el);
187 0 return $el;
188 }
189 }
190  
191 =pod
192 $frame->chgName('ns2.example.com');
193  
194 Change a name of host.
195  
196 =cut
197  
198 0 ▶sub chgName {
Subroutine chgName: not called CC=1 SCAR=6.9
Pod undocumented
199 0 my ($self, $name) = @_;
200 0 my $el = $self->createElement('host:name');
201 0 $el->appendText($name);
202 0 $self->chg->appendChild($el);
203 }
204  
205 =pod
206  
207 =head2 TTL Extension
208  
209 $frame->chgTTLs({
210 A => 3600,
211 AAAA => 900,
212 });
213  
214 Specify TTLs for glue records. The server must support the TTL extension.
215  
216 =cut
217  
218 0 ▶sub chgTTLs {
Subroutine chgTTLs: not called CC=3 SCAR=24.8
Pod undocumented
219 0 my ($self, $ttls) = @_;
220  
221 0 foreach my $type (keys(%{$ttls})) {
222 0 my $ttl = $self->createExtensionElementFor(Net::EPP::Frame::ObjectSpec->xmlns('ttl'))->appendChild($self->createElement('ttl'));
223 0 $ttl->appendText($ttls->{$type});
224 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
225 0 $ttl->setAttribute('for', $type);
226  
227 } else {
228 0 $ttl->setAttribute('for', 'custom');
229 0 $ttl->setAttribute('custom', $type);
230  
231 }
232 }
233 }
234  
235 1 1;
« EPP/Frame/Command/Update.pm ↑ Summary EPP/Frame/Command/Create/Host.pm »