File Coverage

blib/lib/Net/EPP/Frame/Command/Create/Host.pm
Criterion Covered Total %
statement 12 38 31.5
branch 0 2 0.0
condition n/a
subroutine 4 9 44.4
pod 1 4 25.0
total 17 53 32.0


line stmt bran cond sub pod time code
1             package Net::EPP::Frame::Command::Create::Host;
2 1     1   8 use List::Util qw(any);
  1         3  
  1         86  
3 1     1   7 use base qw(Net::EPP::Frame::Command::Create);
  1         2  
  1         123  
4 1     1   6 use Net::EPP::Frame::ObjectSpec;
  1         40  
  1         36  
5 1     1   5 use strict;
  1         2  
  1         594  
6              
7             =pod
8              
9             =head1 NAME
10              
11             Net::EPP::Frame::Command::Create::Host - an instance of L
12             for host objects.
13              
14             =head1 SYNOPSIS
15              
16             use Net::EPP::Frame::Command::Create::Host;
17             use strict;
18              
19             my $create = Net::EPP::Frame::Command::Create::Host->new;
20             $create->setHost('ns1.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:host-1.0"
35             xsi:schemaLocation="urn:ietf:params:xml:ns:host-1.0
36             host-1.0.xsd">
37             ns1.example.uk.com
38            
39            
40             0cf1b8f7e14547d26f03b7641660c641d9e79f45
41            
42            
43              
44              
45             =head1 OBJECT HIERARCHY
46              
47             L
48             +----L
49             +----L
50             +----L
51             +----L
52             +----L
53              
54             =cut
55              
56             sub new {
57 0     0 1   my $package = shift;
58 0           my $self = bless($package->SUPER::new('create'), $package);
59              
60 0           $self->addObject(Net::EPP::Frame::ObjectSpec->spec('host'));
61              
62 0           return $self;
63             }
64              
65             =pod
66              
67             =head1 METHODS
68              
69             my $element = $frame->setHost($host_name);
70              
71             This sets the name of the object to be created. Returns the
72             host:nameE> element.
73              
74             =cut
75              
76             sub setHost {
77 0     0 0   my ($self, $host) = @_;
78              
79 0           my $name = $self->createElement('host:name');
80 0           $name->appendText($host);
81              
82 0           $self->getNode('create')->getChildNodes->shift->appendChild($name);
83              
84 0           return 1;
85             }
86              
87             =pod
88              
89             $frame->setAddr({ 'ip' => '10.0.0.1', 'version' => 'v4' });
90              
91             This adds an IP address to the host object. EPP supports multiple
92             addresses of different versions.
93              
94             =cut
95              
96             sub setAddr {
97 0     0 0   my ($self, @addr) = @_;
98              
99 0           foreach my $ip (@addr) {
100 0           my $hostAttr = $self->createElement('host:addr');
101 0           $hostAttr->appendText($ip->{ip});
102 0           $hostAttr->setAttribute('ip', $ip->{version});
103 0           $self->getNode('create')->getChildNodes->shift->appendChild($hostAttr);
104             }
105 0           return 1;
106             }
107              
108             =pod
109              
110             =head2 TTL Extension
111              
112             $frame->setTTLs({
113             A => 3600,
114             AAAA => 900,
115             });
116              
117             Specify TTLs for glue records. The server must support the
118             TTL extension.
119              
120             =cut
121              
122             sub setTTLs {
123 0     0 0   my ($self, $ttls) = @_;
124              
125 0           foreach my $type (keys(%{$ttls})) {
  0            
126 0           my $ttl = $self->createExtensionElementFor(Net::EPP::Frame::ObjectSpec->xmlns('ttl'))->appendChild($self->createElement('ttl'));
127 0           $ttl->appendText($ttls->{$type});
128 0 0   0     if (any { $type eq $_ } qw(NS DS DNAME A AAAA)) {
  0            
129 0           $ttl->setAttribute('for', $type);
130              
131             } else {
132 0           $ttl->setAttribute('for', 'custom');
133 0           $ttl->setAttribute('custom', $type);
134              
135             }
136             }
137             }
138              
139             1;