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