lib/WWW/Hetzner/Robot/CLI/Cmd/Rdns.pm

filter: Statementstmt 83.7% 36 / 43 Branchbran 72.2% 13 / 18 Conditioncond 54.5% 6 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 71.4% 60 / 84 CC 16 SCAR 23.2
CC
16
Cov
76%
execute
13.8
_list
7.1
BEGIN
1.0
CRAP 10.2
« lib/WWW/Hetzner/CLI/Cmd/LoadBalancerType.pm ↑ Summary lib/WWW/Hetzner/Cloud/API/Servers.pm »
1 package WWW::Hetzner::Robot::CLI::Cmd::Rdns;
2 # ABSTRACT: Robot reverse DNS commands
3  
4 1 our $VERSION = '0.102';
5  
6 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use MooX::Cmd;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use MooX::Options protect_argv => 0, usage_string => 'USAGE: hrobot.pl rdns [<ip> [--ptr <hostname> | --delete]]';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 1 option ptr => (
12 is => 'ro',
13 format => 's',
14 doc => 'Set the PTR record for the given IP',
15 );
16  
17 1 option delete => (
18 is => 'ro',
19 short => 'd',
20 doc => 'Delete the reverse DNS entry of the given IP',
21 default => 0,
22 );
23  
24 5 ▶sub execute {
Subroutine execute: called CC=12 SCAR=26.3
Pod undocumented
25 5 my ($self, $args, $chain) = @_;
26 5 my $root = $chain->[0];
27 5 my $robot = $root->robot;
28  
29 5 my $ip = $args->[0];
30  
31 5 ▶ unless ($ip) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ip) 2 3 5
32 2 ▶ die "An IP address is required with --ptr\n" if defined $self->ptr;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->ptr 1 1 2
33 1 ▶ die "An IP address is required with --delete\n" if $self->delete;
Branch: 1 branch
BranchTrueFalseTotal
if $self->delete 0 1 1
34 1 return $self->_list($robot, $root);
35 }
36  
37 3 ▶ die "--ptr and --delete are mutually exclusive\n"
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->ptr and $self->delete 0 3 3
Condition66%2/3
defined $self->ptr and $self->delete
!ll&&!rl&&r
210
MC/DC0%0/2
defined $self->ptr and $self->delete
defined $self->ptr $self->delete
Truth table66%2/3
A and B
A= defined $self->ptrB= $self->delete
ABresult
0X0
100
111
38 if defined $self->ptr && $self->delete;
39  
40 3 ▶ if ($self->delete) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->delete) 1 2 3
41 1 $robot->rdns->delete($ip);
42 1 ▶ print "Reverse DNS entry for $ip deleted\n" unless $root->output eq 'json';
Branch: 1 branch
BranchTrueFalseTotal
unless $root->output eq "json" 1 0 1
43 1 return;
44 }
45  
46 2 ▶ my $entry = defined $self->ptr
Branch: 1 branch
BranchTrueFalseTotal
defined $self->ptr ? : 1 1 2
47 ? $robot->rdns->update($ip, $self->ptr)
48 : $robot->rdns->get($ip);
49  
50 2 ▶ if ($root->output eq 'json') {
Branch: 1 branch
BranchTrueFalseTotal
if ($root->output eq 'json') { } 0 2 2
51 0 require JSON::MaybeXS;
52 0 print JSON::MaybeXS::encode_json({ ip => $entry->ip, ptr => $entry->ptr });
53 0 print "\n";
54 } else {
55 2 ▶ print "IP: ", $entry->ip // '', "\n";
Condition50%1/2
$entry->ip // ""
l!l
20
MC/DC0%0/1
$entry->ip // ""
$entry->ip
Truth table50%1/2
A
A= $entry->ip
Aresult
11
00
56 2 ▶ print "PTR: ", $entry->ptr // '', "\n";
Condition50%1/2
$entry->ptr // ""
l!l
20
MC/DC0%0/1
$entry->ptr // ""
$entry->ptr
Truth table50%1/2
A
A= $entry->ptr
Aresult
11
00
57 }
58 }
59  
60 1 ▶sub _list {
Subroutine _list: called CC=5 SCAR=19.6
61 1 my ($self, $robot, $root) = @_;
62  
63 1 my $entries = $robot->rdns->list;
64  
65 1 ▶ if ($root->output eq 'json') {
Branch: 1 branch
BranchTrueFalseTotal
if ($root->output eq 'json') { } 0 1 1
66 0 require JSON::MaybeXS;
67 0 print JSON::MaybeXS::encode_json([map { +{
68 0 ip => $_->ip,
69 ptr => $_->ptr,
70 } } @$entries]);
71 0 print "\n";
72 } else {
73 1 printf "%-40s %s\n", 'IP', 'PTR';
74 1 for my $e (@$entries) {
75 2 ▶ printf "%-40s %s\n", $e->ip // '', $e->ptr // '';
Condition50%2/4
$e->ip // ""
l!l
20
$e->ptr // ""
l!l
20
MC/DC0%0/1
$e->ip // ""
$e->ip
MC/DC0%0/1
$e->ptr // ""
$e->ptr
Truth table50%1/2
A
A= $e->ip
Aresult
11
00
Truth table50%1/2
A
A= $e->ptr
Aresult
11
00
76 }
77 }
78 }
79  
80 1 1.
81  
82 __END__
« lib/WWW/Hetzner/CLI/Cmd/LoadBalancerType.pm ↑ Summary lib/WWW/Hetzner/Cloud/API/Servers.pm »