lib/WWW/Hetzner/CLI/Cmd/StorageBox/Cmd/List.pm

filter: Statementstmt 85.7% 30 / 35 Branchbran 50.0% 6 / 12 Conditioncond 30.0% 3 / 10 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 64.7% 44 / 68 CC 13 SCAR 30.5
CC
13
Cov
68%
execute
27.3
BEGIN
1.0
BEGIN
1.0
CRAP 21.1
« lib/WWW/Hetzner/Robot/IP.pm ↑ Summary lib/WWW/Hetzner/CLI/Cmd/StorageBox.pm »
1 package WWW::Hetzner::CLI::Cmd::StorageBox::Cmd::List;
2 # ABSTRACT: List Storage Boxes
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 usage_string => 'USAGE: hcloud.pl storage-box list [options]';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use JSON::MaybeXS qw(encode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 option name => ( is => 'ro', format => 's', short => 'n', doc => 'Filter by Storage Box name' );
12 1 option selector => ( is => 'ro', format => 's', short => 'l', doc => 'Filter by label selector' );
13  
14 1 ▶sub execute {
Subroutine execute: called CC=13 SCAR=33.1
Pod undocumented
15 1 my ($self, $args, $chain) = @_;
16 1 my $main = $chain->[0];
17 1 my %params;
18 1 ▶ $params{name} = $self->name if defined $self->name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->name 0 1 1
19 1 ▶ $params{label_selector} = $self->selector if defined $self->selector;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->selector 0 1 1
20 1 my $boxes = $main->storage->storage_boxes->list_all(%params);
21  
22 1 ▶ if ($main->output eq 'json') {
Branch: 1 branch
BranchTrueFalseTotal
if ($main->output eq "json") 0 1 1
23 0 print encode_json([map { $_->data } @$boxes]), "\n";
24 0 return;
25 }
26 1 ▶ if (!@$boxes) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$boxes) 0 1 1
27 0 print "No Storage Boxes found.\n";
28 0 return;
29 }
30 1 printf "%-10s %-25s %-12s %-12s %s\n", 'ID', 'NAME', 'TYPE', 'LOCATION', 'STATUS';
31 1 print '-' x 78, "\n";
32 1 for my $box (@$boxes) {
33 1 my $type = $box->storage_box_type;
34 1 my $location = $box->location;
35 printf "%-10s %-25s %-12s %-12s %s\n",
36 $box->id,
37 $box->name,
38 ref $type eq 'HASH' ? ($type->{name} // '-') : ($type // '-'),
39 1 ▶ ref $location eq 'HASH' ? ($location->{name} // '-') : ($location // '-'),
Branch: 2 branches
BranchTrueFalseTotal
ref $type eq 'HASH' ? : 1 0 1
ref $location eq 'HASH' ? : 1 0 1
Condition30%3/10
$type->{"name"} // "-"
l!l
10
$type // "-"
l!l
00
$location->{"name"} // "-"
l!l
10
$location // "-"
l!l
00
$box->status // "-"
l!l
10
MC/DC0%0/1
$type->{"name"} // "-"
$type->{"name"}
MC/DC0%0/1
$type // "-"
$type
MC/DC0%0/1
$location->{"name"} // "-"
$location->{"name"}
MC/DC0%0/1
$location // "-"
$location
MC/DC0%0/1
$box->status // "-"
$box->status
Truth table50%1/2
A
A= $type->{"name"}
Aresult
11
00
Truth table0%0/2
A
A= $type
Aresult
11
00
Truth table50%1/2
A
A= $location->{"name"}
Aresult
11
00
Truth table0%0/2
A
A= $location
Aresult
11
00
Truth table50%1/2
A
A= $box->status
Aresult
11
00
40 $box->status // '-';
41 }
42 }
43  
44 1 1;
45  
46 __END__
« lib/WWW/Hetzner/Robot/IP.pm ↑ Summary lib/WWW/Hetzner/CLI/Cmd/StorageBox.pm »