DNS/CLI.pm

filter: Statementstmt 6.2% 17 / 274 Branchbran 0.0% 0 / 166 Conditioncond 0.0% 0 / 42 MC/DCmcdc 0.0% 0 / 27 Subroutinesub 22.7% 5 / 22 Podpod 100% 4 / 4 totaltotal 4.8% 26 / 535 CC 108 SCAR 53.6
CC
108
Cov
4%
zone
462.0
rr
420.0
option
272.0
CRAP 212.0
« DNS/Server.pm ↑ Summary DNS.pm »
1 package Lim::Plugin::DNS::CLI;
2  
3 1 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use Getopt::Long ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Lim::Plugin::DNS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use base qw(Lim::Component::CLI);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =encoding utf8
13  
14 =head1 NAME
15  
16 Lim::Plugin::DNS::CLI - CLI class for DNS Manager Lim plugin
17  
18 =head1 VERSION
19  
20 See L<Lim::Plugin::DNS> for version.
21  
22 =cut
23  
24 1 our $VERSION = $Lim::Plugin::DNS::VERSION;
25  
26 =head1 SYNOPSIS
27  
28 use Lim::Plugin::DNS;
29
30 # Create a CLI object
31 $cli = Lim::Plugin::DNS->CLI;
32  
33 =head1 METHODS
34  
35 These methods are called from the Lim framework and should not be used else
36 where.
37  
38 Please see L<Lim::Plugin::DNS> for full documentation of calls.
39  
40 =over 4
41  
42 =item $cli->zones
43  
44 List existing zones and related software.
45  
46 =cut
47  
48 0 ▶sub zones {
Subroutine zones: not called CC=1 SCAR=6.9
Pod documented
49 0 my ($self) = @_;
50 0 my $dns = Lim::Plugin::DNS->Client;
51
52 0 weaken($self);
53 0 ▶ $dns->ReadZones(sub {
Subroutine __ANON__: not called CC=8 SCAR=42.8
54 0 my ($call, $response) = @_;
55
56 0 ▶ unless (defined $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
57 0 undef($dns);
58 0 return;
59 }
60
61 0 ▶ if ($call->Successful) {
Branch: 1 branch
BranchTrueFalseTotal
if ($call->Successful) { } 0 0 0
62 0 ▶ if (exists $response->{zone}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $response->{"zone"}) 0 0 0
63 0 $self->cli->println(join("\t", 'Software', 'Zone File', 'Read', 'Write'));
64 0 ▶ foreach my $zone (ref($response->{zone}) eq 'ARRAY' ? @{$response->{zone}} : $response->{zone}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $response->{'zone'} eq 'ARRAY' ? : 0 0 0
65 $self->cli->println(join("\t",
66 $zone->{software},
67 $zone->{file},
68 $zone->{read} ? 'Yes' : 'No',
69 0 ▶ $zone->{write} ? 'Yes' : 'No'
Branch: 2 branches
BranchTrueFalseTotal
$zone->{'read'} ? : 0 0 0
$zone->{'write'} ? : 0 0 0
70 ));
71 }
72 }
73 0 $self->Successful;
74 }
75 else {
76 0 $self->Error($call->Error);
77 }
78 0 undef($dns);
79 0 });
80 }
81  
82 =item $cli->zone("create", "[--software <software>] <zone name> <local zone file>")
83  
84 Create a new zone with the content of a local zone file.
85  
86 =item $cli->zone("read", "[--software <software>] <zone names ... >")
87  
88 Read zones and display content.
89  
90 =item $cli->zone("update", "[--software <software>] <zone name> <local zone file>")
91  
92 Update a existing zone with the content of a local zone file.
93  
94 =item $cli->zone("delete", "[--software <software>] <zone name>")
95  
96 Delete the specified zone.
97  
98 =cut
99  
100 0 ▶sub zone {
Subroutine zone: not called CC=21 SCAR=61.4
Pod documented
101 0 my ($self, $cmd) = @_;
102 0 my $software;
103 0 my $as_content = 0;
104 0 my ($getopt, $args) = Getopt::Long::GetOptionsFromString($cmd,
105 'software:s' => \$software
106 );
107  
108 0 ▶ unless ($getopt and scalar @$args) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($getopt and scalar @$args) 0 0 0
Condition0%0/2
$getopt and scalar @$args
!ll
00
MC/DC0%0/1
$getopt and scalar @$args
$getopt
Truth table0%0/2
A
A= $getopt
Aresult
00
11
109 0 $self->Error;
110 0 return;
111 }
112  
113 0 ▶ if ($args->[0] eq 'create' and scalar @$args >= 2) {
Branch: 4 branches
BranchTrueFalseTotal
if ($args->[0] eq 'create' and scalar @$args >= 2) { } 0 0 0
elsif ($args->[0] eq 'read' and scalar @$args >= 2) { } 0 0 0
elsif ($args->[0] eq 'update' and scalar @$args == 3) { } 0 0 0
elsif ($args->[0] eq 'delete' and scalar @$args == 2) { } 0 0 0
Condition0%0/3
$args->[0] eq "create" and scalar @$args >= 2
!ll&&!rl&&r
000
MC/DC0%0/2
$args->[0] eq "create" and scalar @$args >= 2
$args->[0] eq "create" scalar @$args >= 2
Truth table0%0/3
A and B
A= $args->[0] eq "create"B= scalar @$args >= 2
ABresult
0X0
100
111
114 0 my (undef, $zone, $file) = @$args;
115 0 my $content;
116
117 0 ▶ if (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file) 0 0 0
118 0 ▶ unless (defined ($content = Lim::Util::FileReadContent($file))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined($content = Lim::Util::FileReadContent($file))) 0 0 0
119 0 $self->Error('Unable to read file ', $file, ' to create zone ', $zone);
120 0 return;
121 }
122 }
123
124 0 my $dns = Lim::Plugin::DNS->Client;
125 0 weaken($self);
126 $dns->CreateZone({
127 zone => {
128 file => $zone,
129 (defined $software ? (software => $software) : ()),
130 (defined $content ? (content => $content) : ())
131 }
132 0 ▶ }, sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
133 0 my ($call, $response) = @_;
134
135 0 ▶ unless (defined $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
136 0 undef($dns);
137 0 return;
138 }
139
140 0 ▶ if ($call->Successful) {
Branch: 1 branch
BranchTrueFalseTotal
if ($call->Successful) { } 0 0 0
141 0 $self->cli->println('Zone ', $zone, ' created');
142 0 $self->Successful;
143 }
144 else {
145 0 $self->Error($call->Error);
146 }
147 0 undef($dns);
148 0 ▶ });
Branch: 2 branches
BranchTrueFalseTotal
defined $software ? : 0 0 0
defined $content ? : 0 0 0
149 0 return;
150 }
151 ▶ elsif ($args->[0] eq 'read' and scalar @$args >= 2) {
Condition0%0/3
$args->[0] eq "read" and scalar @$args >= 2
!ll&&!rl&&r
000
MC/DC0%0/2
$args->[0] eq "read" and scalar @$args >= 2
$args->[0] eq "read" scalar @$args >= 2
Truth table0%0/3
A and B
A= $args->[0] eq "read"B= scalar @$args >= 2
ABresult
0X0
100
111
152 0 my @zones;
153 0 my $skip = 1;
154
155 0 foreach (@$args) {
156 0 ▶ if ($skip) {
Branch: 1 branch
BranchTrueFalseTotal
if ($skip) 0 0 0
157 0 $skip--;
158 0 next;
159 }
160
161 0 ▶ push(@zones, {
Branch: 1 branch
BranchTrueFalseTotal
defined $software ? : 0 0 0
162 file => $_,
163 (defined $software ? (software => $software) : ())
164 });
165 }
166
167 0 my $dns = Lim::Plugin::DNS->Client;
168 0 weaken($self);
169 $dns->ReadZone({
170 zone => \@zones
171 0 ▶ }, sub {
Subroutine __ANON__: not called CC=13 SCAR=52.0
172 0 my ($call, $response) = @_;
173
174 0 ▶ unless (defined $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
175 0 undef($dns);
176 0 return;
177 }
178
179 0 ▶ if ($call->Successful) {
Branch: 1 branch
BranchTrueFalseTotal
if ($call->Successful) { } 0 0 0
180 0 ▶ if (exists $response->{zone}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $response->{"zone"}) 0 0 0
181 0 ▶ foreach my $zone (ref($response->{zone}) eq 'ARRAY' ? @{$response->{zone}} : $response->{zone}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $response->{'zone'} eq 'ARRAY' ? : 0 0 0
182 0 $self->cli->println('Zone: ', $zone->{file}, ' (', $zone->{software}, ')');
183 0 ▶ if (exists $zone->{content}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $zone->{'content'}) { } 0 0 0
184 0 $self->cli->println($zone->{content});
185 }
186 else {
187 0 ▶ if (exists $zone->{option}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $zone->{"option"}) 0 0 0
188 0 ▶ foreach my $option (ref($zone->{option}) eq 'ARRAY' ? @{$zone->{option}} : $zone->{option}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $zone->{'option'} eq 'ARRAY' ? : 0 0 0
189 $self->cli->println(join("\t",
190 '$'.$option->{name},
191 $option->{value}
192 0 ));
193 }
194 }
195 0 ▶ if (exists $zone->{rr}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $zone->{"rr"}) 0 0 0
196 0 ▶ foreach my $rr (ref($zone->{rr}) eq 'ARRAY' ? @{$zone->{rr}} : $zone->{rr}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $zone->{'rr'} eq 'ARRAY' ? : 0 0 0
197 $self->cli->println(join("\t",
198 $rr->{name},
199 $rr->{ttl},
200 $rr->{class},
201 $rr->{type},
202 $rr->{rdata}
203 0 ));
204 }
205 }
206 }
207 }
208 }
209 0 $self->Successful;
210 }
211 else {
212 0 $self->Error($call->Error);
213 }
214 0 undef($dns);
215 0 });
216 0 return;
217 }
218 ▶ elsif ($args->[0] eq 'update' and scalar @$args == 3) {
Condition0%0/3
$args->[0] eq "update" and scalar @$args == 3
!ll&&!rl&&r
000
MC/DC0%0/2
$args->[0] eq "update" and scalar @$args == 3
$args->[0] eq "update" scalar @$args == 3
Truth table0%0/3
A and B
A= $args->[0] eq "update"B= scalar @$args == 3
ABresult
0X0
100
111
219 0 my (undef, $zone, $file) = @$args;
220 0 my $content;
221
222 0 ▶ unless (defined ($content = Lim::Util::FileReadContent($file))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined($content = Lim::Util::FileReadContent($file))) 0 0 0
223 0 $self->Error('Unable to read file ', $file, ' to update zone ', $zone);
224 0 return;
225 }
226
227 0 my $dns = Lim::Plugin::DNS->Client;
228 0 weaken($self);
229 $dns->UpdateZone({
230 zone => {
231 file => $zone,
232 (defined $software ? (software => $software) : ()),
233 content => $content
234 }
235 0 ▶ }, sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
236 0 my ($call, $response) = @_;
237
238 0 ▶ unless (defined $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
239 0 undef($dns);
240 0 return;
241 }
242
243 0 ▶ if ($call->Successful) {
Branch: 1 branch
BranchTrueFalseTotal
if ($call->Successful) { } 0 0 0
244 0 $self->cli->println('Zone ', $zone, ' updated');
245 0 $self->Successful;
246 }
247 else {
248 0 $self->Error($call->Error);
249 }
250 0 undef($dns);
251 0 ▶ });
Branch: 1 branch
BranchTrueFalseTotal
defined $software ? : 0 0 0
252 0 return;
253 }
254 ▶ elsif ($args->[0] eq 'delete' and scalar @$args == 2) {
Condition0%0/3
$args->[0] eq "delete" and scalar @$args == 2
!ll&&!rl&&r
000
MC/DC0%0/2
$args->[0] eq "delete" and scalar @$args == 2
$args->[0] eq "delete" scalar @$args == 2
Truth table0%0/3
A and B
A= $args->[0] eq "delete"B= scalar @$args == 2
ABresult
0X0
100
111
255 0 my (undef, $zone) = @$args;
256
257 # Ask user
258
259 0 my $dns = Lim::Plugin::DNS->Client;
260 0 weaken($self);
261 $dns->DeleteZone({
262 zone => {
263 file => $zone,
264 (defined $software ? (software => $software) : ())
265 }
266 0 ▶ }, sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
267 0 my ($call, $response) = @_;
268
269 0 ▶ unless (defined $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
270 0 undef($dns);
271 0 return;
272 }
273
274 0 ▶ if ($call->Successful) {
Branch: 1 branch
BranchTrueFalseTotal
if ($call->Successful) { } 0 0 0
275 0 $self->cli->println('Zone ', $zone, ' deleted');
276 0 $self->Successful;
277 }
278 else {
279 0 $self->Error($call->Error);
280 }
281 0 undef($dns);
282 0 ▶ });
Branch: 1 branch
BranchTrueFalseTotal
defined $software ? : 0 0 0
283 0 return;
284 }
285 0 $self->Error;
286 }
287  
288 =item $cli->option("create", "[--software <software>] <zone name> <option name> <option values ... >")
289  
290 Create a new zone option in the an existing zone.
291  
292 =item $cli->option("read", "[--software <software>] <zone name> [option name]")
293  
294 Read and display the specified option, or all if not given, from the zone.
295  
296 =item $cli->option("update", "[--software <software>] <zone name> <option name> <option values ... >")
297  
298 Update an existing option in a zone.
299  
300 =item $cli->option("delete", "[--software <software>] <zone name> <option name>")
301  
302 Delete the specified option from a zone.
303  
304 =cut
305  
306 0 ▶sub option {
Subroutine option: not called CC=16 SCAR=56.1
Pod documented
307 0 my ($self, $cmd) = @_;
308 0 my $software;
309 0 my ($getopt, $args) = Getopt::Long::GetOptionsFromString($cmd,
310 'software:s' => \$software
311 );
312  
313 0 ▶ unless ($getopt and scalar @$args) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($getopt and scalar @$args) 0 0 0
Condition0%0/2
$getopt and scalar @$args
!ll
00
MC/DC0%0/1
$getopt and scalar @$args
$getopt
Truth table0%0/2
A
A= $getopt
Aresult
00
11
314 0 $self->Error;
315 0 return;
316 }
317  
318 0 ▶ if ($args->[0] eq 'create' and scalar @$args >= 4) {
Branch: 4 branches
BranchTrueFalseTotal
if ($args->[0] eq 'create' and scalar @$args >= 4) { } 0 0 0
elsif ($args->[0] eq 'read' and scalar @$args >= 2) { } 0 0 0
elsif ($args->[0] eq 'update' and scalar @$args >= 4) { } 0 0 0
elsif ($args->[0] eq 'delete' and scalar @$args == 3) { } 0 0 0
Condition0%0/3
$args->[0] eq "create" and scalar @$args >= 4
!ll&&!rl&&r
000
MC/DC0%0/2
$args->[0] eq "create" and scalar @$args >= 4
$args->[0] eq "create" scalar @$args >= 4
Truth table0%0/3
A and B
A= $args->[0] eq "create"B= scalar @$args >= 4
ABresult
0X0
100
111
319 0 my (undef, $zone, $name, @value) = @$args;
320 0 my $value = join(' ', @value);
321  
322 0 my $dns = Lim::Plugin::DNS->Client;
323 0 weaken($self);
324 $dns->CreateZoneOption({
325 zone => {
326 file => $zone,
327 (defined $software ? (software => $software) : ()),
328 option => {
329 name => $name,
330 value => $value
331 }
332 }
333 0 ▶ }, sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
334 0 my ($call, $response) = @_;
335
336 0 ▶ unless (defined $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
337 0 undef($dns);
338 0 return;
339 }
340
341 0 ▶ if ($call->Successful) {
Branch: 1 branch
BranchTrueFalseTotal
if ($call->Successful) { } 0 0 0
342 0 $self->cli->println('Zone ', $zone, ' option ', $name, ' created');
343 0 $self->Successful;
344 }
345 else {
346 0 $self->Error($call->Error);
347 }
348 0 undef($dns);
349 0 ▶ });
Branch: 1 branch
BranchTrueFalseTotal
defined $software ? : 0 0 0
350 0 return;
351 }
352 ▶ elsif ($args->[0] eq 'read' and scalar @$args >= 2) {
Condition0%0/3
$args->[0] eq "read" and scalar @$args >= 2
!ll&&!rl&&r
000
MC/DC0%0/2
$args->[0] eq "read" and scalar @$args >= 2
$args->[0] eq "read" scalar @$args >= 2
Truth table0%0/3
A and B
A= $args->[0] eq "read"B= scalar @$args >= 2
ABresult
0X0
100
111
353 0 my (undef, $zone, $name) = @$args;
354  
355 0 my $dns = Lim::Plugin::DNS->Client;
356 0 weaken($self);
357 $dns->ReadZoneOption({
358 zone => {
359 file => $zone,
360 (defined $software ? (software => $software) : ()),
361 (defined $name ? (option => { name => $name }) : ())
362 }
363 0 ▶ }, sub {
Subroutine __ANON__: not called CC=9 SCAR=45.0
364 0 my ($call, $response) = @_;
365
366 0 ▶ unless (defined $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
367 0 undef($dns);
368 0 return;
369 }
370
371 0 ▶ if ($call->Successful) {
Branch: 1 branch
BranchTrueFalseTotal
if ($call->Successful) { } 0 0 0
372 0 ▶ if (exists $response->{zone}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $response->{"zone"}) 0 0 0
373 0 ▶ foreach my $zone (ref($response->{zone}) eq 'ARRAY' ? @{$response->{zone}} : $response->{zone}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $response->{'zone'} eq 'ARRAY' ? : 0 0 0
374 0 $self->cli->println('Zone: ', $zone->{file}, ' (', $zone->{software}, ')');
375 0 ▶ if (exists $zone->{option}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $zone->{"option"}) 0 0 0
376 0 ▶ foreach my $option (ref($zone->{option}) eq 'ARRAY' ? @{$zone->{option}} : $zone->{option}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $zone->{'option'} eq 'ARRAY' ? : 0 0 0
377 $self->cli->println(join("\t",
378 '$'.$option->{name},
379 $option->{value}
380 0 ));
381 }
382 }
383 }
384 }
385 0 $self->Successful;
386 }
387 else {
388 0 $self->Error($call->Error);
389 }
390 0 undef($dns);
391 0 ▶ });
Branch: 2 branches
BranchTrueFalseTotal
defined $software ? : 0 0 0
defined $name ? : 0 0 0
392 0 return;
393 }
394 ▶ elsif ($args->[0] eq 'update' and scalar @$args >= 4) {
Condition0%0/3
$args->[0] eq "update" and scalar @$args >= 4
!ll&&!rl&&r
000
MC/DC0%0/2
$args->[0] eq "update" and scalar @$args >= 4
$args->[0] eq "update" scalar @$args >= 4
Truth table0%0/3
A and B
A= $args->[0] eq "update"B= scalar @$args >= 4
ABresult
0X0
100
111
395 0 my (undef, $zone, $name, @value) = @$args;
396 0 my $value = join(' ', @value);
397  
398 0 my $dns = Lim::Plugin::DNS->Client;
399 0 weaken($self);
400 $dns->UpdateZoneOption({
401 zone => {
402 file => $zone,
403 (defined $software ? (software => $software) : ()),
404 option => {
405 name => $name,
406 value => $value
407 }
408 }
409 0 ▶ }, sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
410 0 my ($call, $response) = @_;
411
412 0 ▶ unless (defined $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
413 0 undef($dns);
414 0 return;
415 }
416
417 0 ▶ if ($call->Successful) {
Branch: 1 branch
BranchTrueFalseTotal
if ($call->Successful) { } 0 0 0
418 0 $self->cli->println('Zone ', $zone, ' option ', $name, ' updated');
419 0 $self->Successful;
420 }
421 else {
422 0 $self->Error($call->Error);
423 }
424 0 undef($dns);
425 0 ▶ });
Branch: 1 branch
BranchTrueFalseTotal
defined $software ? : 0 0 0
426 0 return;
427 }
428 ▶ elsif ($args->[0] eq 'delete' and scalar @$args == 3) {
Condition0%0/3
$args->[0] eq "delete" and scalar @$args == 3
!ll&&!rl&&r
000
MC/DC0%0/2
$args->[0] eq "delete" and scalar @$args == 3
$args->[0] eq "delete" scalar @$args == 3
Truth table0%0/3
A and B
A= $args->[0] eq "delete"B= scalar @$args == 3
ABresult
0X0
100
111
429 0 my (undef, $zone, $name) = @$args;
430  
431 0 my $dns = Lim::Plugin::DNS->Client;
432 0 weaken($self);
433 $dns->DeleteZoneOption({
434 zone => {
435 file => $zone,
436 (defined $software ? (software => $software) : ()),
437 option => {
438 name => $name
439 }
440 }
441 0 ▶ }, sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
442 0 my ($call, $response) = @_;
443
444 0 ▶ unless (defined $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
445 0 undef($dns);
446 0 return;
447 }
448
449 0 ▶ if ($call->Successful) {
Branch: 1 branch
BranchTrueFalseTotal
if ($call->Successful) { } 0 0 0
450 0 $self->cli->println('Zone ', $zone, ' option ', $name, ' deleted');
451 0 $self->Successful;
452 }
453 else {
454 0 $self->Error($call->Error);
455 }
456 0 undef($dns);
457 0 ▶ });
Branch: 1 branch
BranchTrueFalseTotal
defined $software ? : 0 0 0
458 0 return;
459 }
460 0 $self->Error;
461 }
462  
463 =item $cli->rr("create", "[--software <software>] [--ttl <ttl>] [--class <class>] <zone name> <rr name> <rr type> <rr data ... >")
464  
465 Create a new resource record in an existing zone.
466  
467 =item $cli->rr("read", "[--software <software>] <zone name> [rr name]")
468  
469 Read and display the specified resource record, or all if not given, from the zone.
470  
471 =item $cli->rr("update", "[--software <software>] [--ttl <ttl>] [--class <class>] <zone name> <rr name> <rr type> <rr data ... >")
472  
473 Update an existing resource record in a zone.
474  
475 =item $cli->rr("delete", "[--software <software>] <zone name> <rr name>")
476  
477 Delete the specified resource record from a zone.
478  
479 =cut
480  
481 0 ▶sub rr {
Subroutine rr: not called CC=20 SCAR=60.4
Pod documented
482 0 my ($self, $cmd) = @_;
483 0 my $software;
484 my $ttl;
485 0 my $class;
486 0 my ($getopt, $args) = Getopt::Long::GetOptionsFromString($cmd,
487 'software:s' => \$software,
488 'ttl:s' => \$ttl,
489 'class:s' => \$class
490 );
491  
492 0 ▶ unless ($getopt and scalar @$args) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($getopt and scalar @$args) 0 0 0
Condition0%0/2
$getopt and scalar @$args
!ll
00
MC/DC0%0/1
$getopt and scalar @$args
$getopt
Truth table0%0/2
A
A= $getopt
Aresult
00
11
493 0 $self->Error;
494 0 return;
495 }
496  
497 0 ▶ if ($args->[0] eq 'create' and scalar @$args >= 5) {
Branch: 4 branches
BranchTrueFalseTotal
if ($args->[0] eq 'create' and scalar @$args >= 5) { } 0 0 0
elsif ($args->[0] eq 'read' and scalar @$args >= 2) { } 0 0 0
elsif ($args->[0] eq 'update' and scalar @$args >= 5) { } 0 0 0
elsif ($args->[0] eq 'delete' and scalar @$args == 3) { } 0 0 0
Condition0%0/3
$args->[0] eq "create" and scalar @$args >= 5
!ll&&!rl&&r
000
MC/DC0%0/2
$args->[0] eq "create" and scalar @$args >= 5
$args->[0] eq "create" scalar @$args >= 5
Truth table0%0/3
A and B
A= $args->[0] eq "create"B= scalar @$args >= 5
ABresult
0X0
100
111
498 0 my (undef, $zone, $name, $type, @rdata) = @$args;
499 0 my $rdata = join(' ', @rdata);
500  
501 0 my $dns = Lim::Plugin::DNS->Client;
502 0 weaken($self);
503 $dns->CreateZoneRr({
504 zone => {
505 file => $zone,
506 (defined $software ? (software => $software) : ()),
507 rr => {
508 name => $name,
509 (defined $ttl ? (ttl => $ttl) : ()),
510 (defined $class ? (class => $class) : ()),
511 type => $type,
512 rdata => $rdata
513 }
514 }
515 0 ▶ }, sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
516 0 my ($call, $response) = @_;
517
518 0 ▶ unless (defined $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
519 0 undef($dns);
520 0 return;
521 }
522
523 0 ▶ if ($call->Successful) {
Branch: 1 branch
BranchTrueFalseTotal
if ($call->Successful) { } 0 0 0
524 0 $self->cli->println('Zone ', $zone, ' RR ', $name, ' created');
525 0 $self->Successful;
526 }
527 else {
528 0 $self->Error($call->Error);
529 }
530 0 undef($dns);
531 0 ▶ });
Branch: 3 branches
BranchTrueFalseTotal
defined $software ? : 0 0 0
defined $ttl ? : 0 0 0
defined $class ? : 0 0 0
532 0 return;
533 }
534 ▶ elsif ($args->[0] eq 'read' and scalar @$args >= 2) {
Condition0%0/3
$args->[0] eq "read" and scalar @$args >= 2
!ll&&!rl&&r
000
MC/DC0%0/2
$args->[0] eq "read" and scalar @$args >= 2
$args->[0] eq "read" scalar @$args >= 2
Truth table0%0/3
A and B
A= $args->[0] eq "read"B= scalar @$args >= 2
ABresult
0X0
100
111
535 0 my (undef, $zone, $name) = @$args;
536  
537 0 my $dns = Lim::Plugin::DNS->Client;
538 0 weaken($self);
539 $dns->ReadZoneRr({
540 zone => {
541 file => $zone,
542 (defined $software ? (software => $software) : ()),
543 (defined $name ? (rr => { name => $name }) : ())
544 }
545 0 ▶ }, sub {
Subroutine __ANON__: not called CC=9 SCAR=45.0
546 0 my ($call, $response) = @_;
547
548 0 ▶ unless (defined $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
549 0 undef($dns);
550 0 return;
551 }
552
553 0 ▶ if ($call->Successful) {
Branch: 1 branch
BranchTrueFalseTotal
if ($call->Successful) { } 0 0 0
554 0 ▶ if (exists $response->{zone}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $response->{"zone"}) 0 0 0
555 0 ▶ foreach my $zone (ref($response->{zone}) eq 'ARRAY' ? @{$response->{zone}} : $response->{zone}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $response->{'zone'} eq 'ARRAY' ? : 0 0 0
556 0 $self->cli->println('Zone: ', $zone->{file}, ' (', $zone->{software}, ')');
557 0 ▶ if (exists $zone->{rr}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $zone->{"rr"}) 0 0 0
558 0 ▶ foreach my $rr (ref($zone->{rr}) eq 'ARRAY' ? @{$zone->{rr}} : $zone->{rr}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $zone->{'rr'} eq 'ARRAY' ? : 0 0 0
559 $self->cli->println(join("\t",
560 $rr->{name},
561 $rr->{ttl},
562 $rr->{class},
563 $rr->{type},
564 $rr->{rdata}
565 0 ));
566 }
567 }
568 }
569 }
570 0 $self->Successful;
571 }
572 else {
573 0 $self->Error($call->Error);
574 }
575 0 undef($dns);
576 0 ▶ });
Branch: 2 branches
BranchTrueFalseTotal
defined $software ? : 0 0 0
defined $name ? : 0 0 0
577 0 return;
578 }
579 ▶ elsif ($args->[0] eq 'update' and scalar @$args >= 5) {
Condition0%0/3
$args->[0] eq "update" and scalar @$args >= 5
!ll&&!rl&&r
000
MC/DC0%0/2
$args->[0] eq "update" and scalar @$args >= 5
$args->[0] eq "update" scalar @$args >= 5
Truth table0%0/3
A and B
A= $args->[0] eq "update"B= scalar @$args >= 5
ABresult
0X0
100
111
580 0 my (undef, $zone, $name, $type, @rdata) = @$args;
581 0 my $rdata = join(' ', @rdata);
582  
583 0 my $dns = Lim::Plugin::DNS->Client;
584 0 weaken($self);
585 $dns->UpdateZoneRr({
586 zone => {
587 file => $zone,
588 (defined $software ? (software => $software) : ()),
589 rr => {
590 name => $name,
591 (defined $ttl ? (ttl => $ttl) : ()),
592 (defined $class ? (class => $class) : ()),
593 type => $type,
594 rdata => $rdata
595 }
596 }
597 0 ▶ }, sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
598 0 my ($call, $response) = @_;
599
600 0 ▶ unless (defined $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
601 0 undef($dns);
602 0 return;
603 }
604
605 0 ▶ if ($call->Successful) {
Branch: 1 branch
BranchTrueFalseTotal
if ($call->Successful) { } 0 0 0
606 0 $self->cli->println('Zone ', $zone, ' RR ', $name, ' updated');
607 0 $self->Successful;
608 }
609 else {
610 0 $self->Error($call->Error);
611 }
612 0 undef($dns);
613 0 ▶ });
Branch: 3 branches
BranchTrueFalseTotal
defined $software ? : 0 0 0
defined $ttl ? : 0 0 0
defined $class ? : 0 0 0
614 0 return;
615 }
616 ▶ elsif ($args->[0] eq 'delete' and scalar @$args == 3) {
Condition0%0/3
$args->[0] eq "delete" and scalar @$args == 3
!ll&&!rl&&r
000
MC/DC0%0/2
$args->[0] eq "delete" and scalar @$args == 3
$args->[0] eq "delete" scalar @$args == 3
Truth table0%0/3
A and B
A= $args->[0] eq "delete"B= scalar @$args == 3
ABresult
0X0
100
111
617 0 my (undef, $zone, $name) = @$args;
618  
619 0 my $dns = Lim::Plugin::DNS->Client;
620 0 weaken($self);
621 $dns->DeleteZoneRr({
622 zone => {
623 file => $zone,
624 (defined $software ? (software => $software) : ()),
625 rr => {
626 name => $name
627 }
628 }
629 0 ▶ }, sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
630 0 my ($call, $response) = @_;
631
632 0 ▶ unless (defined $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
633 0 undef($dns);
634 0 return;
635 }
636
637 0 ▶ if ($call->Successful) {
Branch: 1 branch
BranchTrueFalseTotal
if ($call->Successful) { } 0 0 0
638 0 $self->cli->println('Zone ', $zone, ' RR ', $name, ' deleted');
639 0 $self->Successful;
640 }
641 else {
642 0 $self->Error($call->Error);
643 }
644 0 undef($dns);
645 0 ▶ });
Branch: 1 branch
BranchTrueFalseTotal
defined $software ? : 0 0 0
646 0 return;
647 }
648 0 $self->Error;
649 }
650  
651 =back
652  
653 =head1 AUTHOR
654  
655 Jerry Lundström, C<< <lundstrom.jerry at gmail.com> >>
656  
657 =head1 BUGS
658  
659 Please report any bugs or feature requests to L<https://github.com/jelu/lim-plugin-dns/issues>.
660  
661 =head1 SUPPORT
662  
663 You can find documentation for this module with the perldoc command.
664  
665 perldoc Lim::Plugin::DNS
666  
667 You can also look for information at:
668  
669 =over 4
670  
671 =item * Lim issue tracker (report bugs here)
672  
673 L<https://github.com/jelu/lim-plugin-dns/issues>
674  
675 =back
676  
677 =head1 ACKNOWLEDGEMENTS
678  
679 =head1 LICENSE AND COPYRIGHT
680  
681 Copyright 2012-2013 Jerry Lundström.
682  
683 This program is free software; you can redistribute it and/or modify it
684 under the terms of either: the GNU General Public License as published
685 by the Free Software Foundation; or the Artistic License.
686  
687 See http://dev.perl.org/licenses/ for more information.
688  
689  
690 =cut
691  
692 1 1; # End of Lim::Plugin::DNS::CLI
« DNS/Server.pm ↑ Summary DNS.pm »