File Coverage

blib/lib/Net/EPP/Frame/Command/Create/Domain.pm
Criterion Covered Total %
statement 12 95 12.6
branch 0 10 0.0
condition 0 6 0.0
subroutine 4 17 23.5
pod 1 12 8.3
total 17 140 12.1


line stmt bran cond sub pod time code
1             package Net::EPP::Frame::Command::Create::Domain;
2 1     1   8 use List::Util qw(any);
  1         3  
  1         136  
3 1     1   8 use base qw(Net::EPP::Frame::Command::Create);
  1         2  
  1         131  
4 1     1   7 use Net::EPP::Frame::ObjectSpec;
  1         2  
  1         45  
5 1     1   5 use strict;
  1         3  
  1         1457  
6              
7             =pod
8              
9             =head1 NAME
10              
11             Net::EPP::Frame::Command::Create::Domain - an instance of L
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            
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: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             example-1.tldE/domain: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('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             Cdomain:nameE> element.
72              
73             =cut
74              
75             sub setDomain {
76 0     0 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             sub setPeriod {
97 0     0 0   my ($self, $period, $unit) = @_;
98              
99 0 0 0       $unit = 'y' if (!defined($unit) || $unit eq '');
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             sub setRegistrant {
121 0     0 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             sub setContacts {
146 0     0 0   my ($self, $contacts) = @_;
147 0           my $parent = $self->getNode('create')->getChildNodes->shift;
148              
149 0           foreach my $type (keys(%{$contacts})) {
  0            
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             sub setNS {
176 0     0 0   my ($self, @ns) = @_;
177              
178 0 0         if (ref $ns[0] eq 'HASH') {
179 0           $self->addHostAttrNS(@ns);
180             } else {
181 0           $self->addHostObjNS(@ns);
182             }
183              
184 0           return 1;
185             }
186              
187             sub addHostAttrNS {
188 0     0 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 0 0       if (exists $host->{addrs} && ref $host->{addrs} eq 'ARRAY') {
203 0           foreach my $addr (@{$host->{addrs}}) {
  0            
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             sub addHostObjNS {
219 0     0 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             sub setAuthInfo {
232 0     0 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             sub appendStatus {
241 0     0 0   my ($self, $status) = @_;
242 0           return $self->addEl('status', $status);
243             }
244              
245             sub addEl {
246 0     0 0   my ($self, $name, $value) = @_;
247              
248 0           my $el = $self->createElement('domain:' . $name);
249 0 0         $el->appendText($value) if defined($value);
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             sub setTTLs {
272 0     0 0   my ($self, $ttls) = @_;
273              
274 0           foreach my $type (keys(%{$ttls})) {
  0            
275 0           my $ttl = $self->createExtensionElementFor(Net::EPP::Frame::ObjectSpec->xmlns('ttl'))->appendChild($self->createElement('ttl'));
276 0           $ttl->appendText($ttls->{$type});
277 0 0   0     if (any { $type eq $_ } qw(NS DS DNAME A AAAA)) {
  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;