blib/lib/WWW/LogicBoxes/Role/Command/Domain/PrivateNameServer.pm

filter: Statementstmt 34.1% 27 / 79 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 34.7% 8 / 23 Podpod 100% 5 / 5 totaltotal 28.1% 40 / 142 CC 18 SCAR 28.7
CC
18
Cov
24%
__ANON__
56.0
__ANON__
30.0
__ANON__
20.0
CRAP 17.7
« blib/lib/WWW/LogicBoxes/Role/Command/Customer.pm ↑ Summary blib/lib/WWW/LogicBoxes/Domain/Factory.pm »
1 package WWW::LogicBoxes::Role::Command::Domain::PrivateNameServer;
2  
3 36 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 36 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 36 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 36 ▶use MooseX::Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 36 ▶use WWW::LogicBoxes::Types qw( DomainName Int IPv4 PrivateNameServer );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 36 ▶use WWW::LogicBoxes::PrivateNameServer;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 36 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 36 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 36 requires 'submit', 'get_domain_by_id';
17  
18 36 our $VERSION = '1.1.0'; # VERSION
19 # ABSTRACT: Domain Private Nameserver API Calls
20  
21 sub create_private_nameserver {
22 0 ▶ my $self = shift;
Subroutine create_private_nameserver: not called CC=1 SCAR=6.9
Pod documented
23 0 my ( $nameserver ) = pos_validated_list( \@_, { isa => PrivateNameServer, coerce => 1 } );
24  
25 return try {
26 0 ▶ $self->submit({
Subroutine __ANON__: not called CC=1 SCAR=6.9
27 method => 'domains__add_cns',
28 params => {
29 'order-id' => $nameserver->domain_id,
30 'cns' => $nameserver->name,
31 'ip' => $nameserver->ips,
32 }
33 });
34  
35 0 return $self->get_domain_by_id( $nameserver->domain_id );
36 }
37 catch {
38 0 ▶ if( $_ =~ m/^No Entity found for Entityid/ ) {
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 2 branches
BranchTrueFalseTotal
if ($_ =~ /^No Entity found for Entityid/) { } 0 0 0
elsif ($_ =~ /This IpAddress already exists/) { } 0 0 0
39 0 croak 'No such domain';
40 }
41 elsif( $_ =~ m/This IpAddress already exists/ ) {
42 0 croak 'Nameserver with this IP Address already exists';
43 }
44  
45 0 croak $_;
46 0 };
47 }
48  
49 sub rename_private_nameserver {
50 0 ▶ my $self = shift;
Subroutine rename_private_nameserver: not called CC=1 SCAR=6.9
Pod documented
51 0 my ( %args ) = validated_hash(
52 \@_,
53 domain_id => { isa => Int },
54 old_name => { isa => DomainName },
55 new_name => { isa => DomainName },
56 );
57  
58 return try {
59 $self->submit({
60 method => 'domains__modify_cns_name',
61 params => {
62 'order-id' => $args{domain_id},
63 'old-cns' => $args{old_name},
64 'new-cns' => $args{new_name},
65 }
66 0 ▶ });
Subroutine __ANON__: not called CC=1 SCAR=6.9
67  
68 0 return $self->get_domain_by_id( $args{domain_id} );
69 }
70 catch {
71 ## no critic (ControlStructures::ProhibitCascadingIfElse RegularExpressions::ProhibitComplexRegexes)
72 0 ▶ if( $_ =~ m/^No Entity found for Entityid/ ) {
Subroutine __ANON__: not called CC=7 SCAR=40.3
Branch: 5 branches
BranchTrueFalseTotal
if ($_ =~ /^No Entity found for Entityid/) { } 0 0 0
elsif ($_ =~ /^Invalid Old Child NameServer. Its not registered nameserver for this domain/) { } 0 0 0
elsif ($_ =~ /^Parent Domain for New child nameServer is not registered by us/ or $_ =~ /^\{hostname=Parent DomainName is not registered by you\}/) { } 0 0 0
elsif ($_ =~ /^Same value for new and old Child NameServer/) { } 0 0 0
elsif ($_ =~ /^\{hostname=Child NameServer already exists\}/) { } 0 0 0
73 0 croak 'No such domain';
74 }
75 elsif( $_ =~ m/^Invalid Old Child NameServer. Its not registered nameserver for this domain/ ) {
76 0 croak 'No such existing private nameserver';
77 }
78 ▶ elsif( $_ =~ m/^Parent Domain for New child nameServer is not registered by us/
Condition0%0/3
$_ =~ /^Parent Domain for New child nameServer is not registered by us/ or $_ =~ /^\{hostname=Parent DomainName is not registered by you\}/
l!l&&r!l&&!r
000
MC/DC0%0/2
$_ =~ /^Parent Domain for New child nameServer is not registered by us/ or $_ =~ /^\{hostname=Parent DomainName is not registered by you\}/
$_ =~ /^Parent Domain for New child nameServer is not registered by us/ $_ =~ /^\{hostname=Parent DomainName is not registered by you\}/
Truth table0%0/3
A or B
A= $_ =~ /^Parent Domain for New child nameServer is not registered by us/B= $_ =~ /^\{hostname=Parent DomainName is not registered by you\}/
ABresult
1X1
011
000
79 || $_ =~ m/^\{hostname=Parent DomainName is not registered by you\}/ ) {
80 0 croak 'Invalid domain for private nameserver';
81 }
82 elsif( $_ =~ m/^Same value for new and old Child NameServer/ ) {
83 0 croak 'Same value for old and new private nameserver name';
84 }
85 elsif( $_ =~ m/^\{hostname=Child NameServer already exists\}/ ) {
86 0 croak 'A nameserver with that name already exists';
87 }
88 ## use critic
89  
90 0 croak $_;
91 0 };
92 }
93  
94 sub modify_private_nameserver_ip {
95 0 ▶ my $self = shift;
Subroutine modify_private_nameserver_ip: not called CC=1 SCAR=6.9
Pod documented
96 0 my ( %args ) = validated_hash(
97 \@_,
98 domain_id => { isa => Int },
99 name => { isa => DomainName },
100 old_ip => { isa => IPv4 },
101 new_ip => { isa => IPv4 },
102 );
103  
104 return try {
105 $self->submit({
106 method => 'domains__modify_cns_ip',
107 params => {
108 'order-id' => $args{domain_id},
109 'cns' => $args{name},
110 'old-ip' => $args{old_ip},
111 'new-ip' => $args{new_ip},
112 }
113 0 ▶ });
Subroutine __ANON__: not called CC=1 SCAR=6.9
114  
115 0 return $self->get_domain_by_id( $args{domain_id} );
116 }
117 catch {
118 ## no critic (ControlStructures::ProhibitCascadingIfElse RegularExpressions::ProhibitComplexRegexes)
119 0 ▶ if( $_ =~ m/^No Entity found for Entityid/ ) {
Subroutine __ANON__: not called CC=5 SCAR=34.0
Branch: 4 branches
BranchTrueFalseTotal
if ($_ =~ /^No Entity found for Entityid/) { } 0 0 0
elsif ($_ =~ /^Invalid Child Name Server. Its not registered nameserver for this domain/) { } 0 0 0
elsif ($_ =~ /^Same value for new and old IpAddress/) { } 0 0 0
elsif ($_ =~ /^Invalid Old IpAddress. Its not attached to Nameserver/) { } 0 0 0
120 0 croak 'No such domain';
121 }
122 elsif( $_ =~ m/^Invalid Child Name Server. Its not registered nameserver for this domain/ ) {
123 0 croak 'No such existing private nameserver';
124 }
125 elsif( $_ =~ m/^Same value for new and old IpAddress/ ) {
126 0 croak 'Same value for old and new private nameserver ip';
127 }
128 elsif( $_ =~ m/^Invalid Old IpAddress. Its not attached to Nameserver/ ) {
129 0 croak 'Nameserver does not have specified ip';
130 }
131 ## use critic
132  
133 0 croak $_;
134 0 };
135 }
136  
137 sub delete_private_nameserver_ip {
138 0 ▶ my $self = shift;
Subroutine delete_private_nameserver_ip: not called CC=1 SCAR=6.9
Pod documented
139 0 my ( %args ) = validated_hash(
140 \@_,
141 domain_id => { isa => Int },
142 name => { isa => DomainName },
143 ip => { isa => IPv4 },
144 );
145  
146 return try {
147 $self->submit({
148 method => 'domains__delete_cns_ip',
149 params => {
150 'order-id' => $args{domain_id},
151 'cns' => $args{name},
152 'ip' => $args{ip},
153 }
154 0 ▶ });
Subroutine __ANON__: not called CC=1 SCAR=6.9
155  
156 0 return $self->get_domain_by_id( $args{domain_id} );
157 }
158 catch {
159 ## no critic (ControlStructures::ProhibitCascadingIfElse RegularExpressions::ProhibitComplexRegexes)
160 0 ▶ if( $_ =~ m/^No Entity found for Entityid/ ) {
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 3 branches
BranchTrueFalseTotal
if ($_ =~ /^No Entity found for Entityid/) { } 0 0 0
elsif ($_ =~ /^Invalid Child Name Server. Its not registered nameserver for this domain/) { } 0 0 0
elsif ($_ =~ /^\{ipaddress1=Invalid IpAddress .* Its not attached to Nameserver\}/) { } 0 0 0
161 0 croak 'No such domain';
162 }
163 elsif( $_ =~ m/^Invalid Child Name Server. Its not registered nameserver for this domain/ ) {
164 0 croak 'No such existing private nameserver';
165 }
166 elsif( $_ =~ m/^\{ipaddress1=Invalid IpAddress .* Its not attached to Nameserver\}/ ) {
167 0 croak 'IP address not assigned to private nameserver';
168 }
169 ## use critic
170  
171 0 croak $_;
172 0 };
173 }
174  
175 sub delete_private_nameserver {
176 0 ▶ my $self = shift;
Subroutine delete_private_nameserver: not called CC=1 SCAR=6.9
Pod documented
177 0 my ( $nameserver ) = pos_validated_list( \@_, { isa => PrivateNameServer, coerce => 1 } );
178  
179 return try {
180 0 ▶ for my $ip (@{ $nameserver->ips } ) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
181 0 $self->delete_private_nameserver_ip(
182 domain_id => $nameserver->domain_id,
183 name => $nameserver->name,
184 ip => $ip,
185 );
186 }
187  
188 0 return $self->get_domain_by_id( $nameserver->domain_id );
189 }
190 catch {
191 0 ▶ if( $_ =~ m/^No Entity found for Entityid/ ) {
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /^No Entity found for Entityid/) 0 0 0
192 0 croak 'No such domain';
193 }
194  
195 0 croak $_;
196 0 };
197 }
198  
199 36 1;
200  
201 __END__
202 =pod
203  
204 =head1 NAME
205  
206 WWW::LogicBoxes::Role::Command::Domain::PrivateNameServer - Private Nameserver Related Operations
207  
208 =head1 SYNOPSIS
209  
210 use WWW::LogicBoxes;
211 use WWW::LogicBoxes::Domain;
212 use WWW::LogicBoxes::PrivateNameServer;
213  
214 my $logic_boxes = WWW::LogicBoxes->new( ... );
215 my $domain = WWW::LogicBoxes::Domain->new( ... );
216  
217 # Creation
218 my $private_nameserver = WWW::LogicBoxes::PrivateNameServer->new(
219 domain_id => $domain->id,
220 name => 'ns1.' . $domain->name,
221 ips => [ '4.2.2.1' ],
222 );
223  
224 $logic_boxes->create_private_nameserver( $private_nameserver );
225  
226 # Rename
227 $logic_boxes->rename_private_nameserver(
228 domain_id => $domain->id,
229 old_name => 'ns1.' . $domain->name,
230 new_name => 'ns2.' . $domain->name,
231 );
232  
233 # Modify IP
234 $logic_boxes->modify_private_nameserver_ip(
235 domain_id => $domain->id,
236 name => 'ns1.' . $domain->name,
237 old_ip => '4.2.2.1',
238 new_ip => '8.8.8.8',
239 );
240  
241 # Delete IP
242 $logic_boxes->delete_private_nameserver_ip(
243 domain_id => $domain->id,
244 name => 'ns1.' . $domain->name,
245 ip => '4.2.2.1',
246 );
247  
248 # Delete Private Nameserver
249 my $private_nameserver = WWW::LogicBoxes::PrivateNameServer->new( ... );
250 $logic_boxes->delete_private_nameserver( $private_nameserver )
251  
252 =head1 REQUIRES
253  
254 =over 4
255  
256 =item submit
257  
258 =item get_domain_by_id
259  
260 =back
261  
262 =head1 DESCRIPTION
263  
264 Implementes Private Nameserver related operations (what L<LogicBoxes|http://www.logicboxes.com> refers to as "Child Nameservers") with the L<LogicBoxes|http://www.logicboxes.com> API.
265  
266 B<NOTE> All private nameservers must be a subdomain of the parent domain. If the domain name is test-domain.com, ns1.test-domain.com would be valid while ns1.something-else.com would not be.
267  
268 =head1 METHOD
269  
270 =head2 create_private_nameserver
271  
272 use WWW::LogicBoxes;
273 use WWW::LogicBoxes::Domain;
274 use WWW::LogicBoxes::PrivateNameServer;
275  
276 my $logic_boxes = WWW::LogicBoxes->new( ... );
277 my $domain = WWW::LogicBoxes::Domain->new( ... );
278  
279 my $private_nameserver = WWW::LogicBoxes::PrivateNameServer->new(
280 domain_id => $domain->id,
281 name => 'ns1.' . $domain->name,
282 ips => [ '4.2.2.1' ],
283 );
284  
285 $logic_boxes->create_private_nameserver( $private_nameserver );
286  
287 Given a L<WWW::LogicBoxes::PrivateNameServer> or a HashRef that can be coerced into a L<WWW::LogicBoxes::PrivateNameServer>, creates the specified private nameserver with L<LogicBoxes|http://www.logicboxes.com>.
288  
289 =head2 rename_private_nameserver
290  
291 use WWW::LogicBoxes;
292 use WWW::LogicBoxes::Domain;
293  
294 my $domain = WWW::LogicBoxes::Domain->new( ... );
295  
296 $logic_boxes->rename_private_nameserver(
297 domain_id => $domain->id,
298 old_name => 'ns1.' . $domain->name,
299 new_name => 'ns2.' . $domain->name,
300 );
301  
302 Given an Integer L<domain|WWW::LogicBoxes::Domain> id, the old nameserver hostname, and a new nameserver hostname, renames a L<WWW::LogicBoxes::PrivateNameServer>.
303  
304 =head2 modify_private_nameserver_ip
305  
306 use WWW::LogicBoxes;
307 use WWW::LogicBoxes::Domain;
308  
309 my $domain = WWW::LogicBoxes::Domain->new( ... );
310  
311 $logic_boxes->modify_private_nameserver_ip(
312 domain_id => $domain->id,
313 name => 'ns1.' . $domain->name,
314 old_ip => '4.2.2.1',
315 new_ip => '8.8.8.8',
316 );
317  
318 Given an Integer L<domain|WWW::LogicBoxes::Domain> id, nameserver hostname, an old_ip (that is currently assigned to the L<private nameserver|WWW::LogicBoxes::PrivateNameServer>), and a new_ip, modifies the ips assoicated with a L<WWW::LogicBoxes::PrivateNameServer>.
319  
320 =head2 delete_private_nameserver_ip
321  
322 use WWW::LogicBoxes;
323 use WWW::LogicBoxes::Domain;
324  
325 my $domain = WWW::LogicBoxes::Domain->new( ... );
326  
327 $logic_boxes->delete_private_nameserver_ip(
328 domain_id => $domain->id,
329 name => 'ns1.' . $domain->name,
330 ip => '4.2.2.1',
331 );
332  
333 Given an Integer L<domain|WWW::LogicBoxes::Domain> id, nameserver hostname, and an ip (that is currently assigned to the L<private nameserver|WWW::LogicBoxes::PrivateNameServer>), removes the ip assoicated with a L<WWW::LogicBoxes::PrivateNameServer>.
334  
335 =head2 delete_private_nameserver
336  
337 use WWW::LogicBoxes;
338 use WWW::LogicBoxes::Domain;
339 use WWW::LogicBoxes::PrivateNameServer;
340  
341 my $domain = WWW::LogicBoxes::Domain->new( ... );
342  
343 my $private_nameserver = WWW::LogicBoxes::PrivateNameServer->new( ... );
344 $logic_boxes->delete_private_nameserver( $private_nameserver )
345  
346  
347 Given a L<WWW::LogicBoxes::PrivateNameServer> or a HashRef that can be coerced into a L<WWW::LogicBoxes::PrivateNameServer>, deletes the specified private nameserver with L<LogicBoxes|http://www.logicboxes.com>.
348  
349 =cut
« blib/lib/WWW/LogicBoxes/Role/Command/Customer.pm ↑ Summary blib/lib/WWW/LogicBoxes/Domain/Factory.pm »