File Coverage

blib/lib/Net/EPP/Frame/Command/Update/Host.pm
Criterion Covered Total %
statement 12 73 16.4
branch 0 6 0.0
condition n/a
subroutine 4 14 28.5
pod 1 9 11.1
total 17 102 16.6


line stmt bran cond sub pod time code
1             package Net::EPP::Frame::Command::Update::Host;
2 1     1   7 use List::Util qw(any);
  1         3  
  1         91  
3 1     1   8 use base qw(Net::EPP::Frame::Command::Update);
  1         2  
  1         127  
4 1     1   8 use Net::EPP::Frame::ObjectSpec;
  1         2  
  1         24  
5 1     1   5 use strict;
  1         2  
  1         1099  
6              
7             =pod
8              
9             =head1 NAME
10              
11             Net::EPP::Frame::Command::Update::Host - an instance of L
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            
27            
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            
32            
33            
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             example-1.tldE/host:name>
38            
39            
40             0cf1b8f7e14547d26f03b7641660c641d9e79f45
41            
42            
43              
44             =head1 OBJECT HIERARCHY
45              
46             L
47             +----L
48             +----L
49             +----L
50             +----L
51             +----L
52              
53             =cut
54              
55             sub new {
56 0     0 1   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             sub setHost {
82 0     0 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             sub addStatus {
102 0     0 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 0         if ($info) {
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             sub remStatus {
122 0     0 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             sub addAddr {
139 0     0 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             sub remAddr {
160 0     0 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             sub chg {
179 0     0 0   my $self = shift;
180              
181 0           my $chg = $self->getElementsByLocalName('host:chg')->shift;
182 0 0         if ($chg) {
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             sub chgName {
199 0     0 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             sub chgTTLs {
219 0     0 0   my ($self, $ttls) = @_;
220              
221 0           foreach my $type (keys(%{$ttls})) {
  0            
222 0           my $ttl = $self->createExtensionElementFor(Net::EPP::Frame::ObjectSpec->xmlns('ttl'))->appendChild($self->createElement('ttl'));
223 0           $ttl->appendText($ttls->{$type});
224 0 0   0     if (any { $type eq $_ } qw(NS DS DNAME A AAAA)) {
  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;