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

filter: Statementstmt 86.4% 32 / 37 Branchbran 50.0% 6 / 12 Conditioncond 30.0% 3 / 10 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 66.2% 47 / 71 CC 13 SCAR 30.0
CC
13
Cov
69%
_list
27.3
BEGIN
1.0
BEGIN
1.0
CRAP 20.0
« lib/WWW/Hetzner/CLI/Cmd/StorageBox/Cmd/List.pm ↑ Summary lib/WWW/Hetzner/CLI/Cmd/PrimaryIp/Cmd/Describe.pm »
1 package WWW::Hetzner::CLI::Cmd::StorageBox;
2 # ABSTRACT: Storage Box 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 usage_string => 'USAGE: hcloud.pl storage-box <command> [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  
12 1 option name => (
13 is => 'ro',
14 format => 's',
15 short => 'n',
16 doc => 'Filter by Storage Box name',
17 );
18  
19 1 option selector => (
20 is => 'ro',
21 format => 's',
22 short => 'l',
23 doc => 'Filter by label selector',
24 );
25  
26 1 ▶sub execute {
Subroutine execute: called CC=1 SCAR=0.0
Pod undocumented
27 1 my ($self, $args, $chain) = @_;
28 1 $self->_list($chain);
29 }
30  
31 1 ▶sub _list {
Subroutine _list: called CC=13 SCAR=33.1
32 1 my ($self, $chain) = @_;
33 1 my $main = $chain->[0];
34 1 my %params;
35 1 ▶ $params{name} = $self->name if defined $self->name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->name 0 1 1
36 1 ▶ $params{label_selector} = $self->selector if defined $self->selector;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->selector 0 1 1
37 1 my $boxes = $main->storage->storage_boxes->list_all(%params);
38  
39 1 ▶ if ($main->output eq 'json') {
Branch: 1 branch
BranchTrueFalseTotal
if ($main->output eq "json") 0 1 1
40 0 print encode_json([map { $_->data } @$boxes]), "\n";
41 0 return;
42 }
43  
44 1 ▶ if (!@$boxes) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$boxes) 0 1 1
45 0 print "No Storage Boxes found.\n";
46 0 return;
47 }
48  
49 1 printf "%-10s %-25s %-12s %-12s %s\n", 'ID', 'NAME', 'TYPE', 'LOCATION', 'STATUS';
50 1 print '-' x 78, "\n";
51 1 for my $box (@$boxes) {
52 1 my $type = $box->storage_box_type;
53 1 my $location = $box->location;
54 printf "%-10s %-25s %-12s %-12s %s\n",
55 $box->id,
56 $box->name,
57 ref $type eq 'HASH' ? ($type->{name} // '-') : ($type // '-'),
58 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
59 $box->status // '-';
60 }
61 }
62  
63  
64 1 1;
65  
66 __END__
« lib/WWW/Hetzner/CLI/Cmd/StorageBox/Cmd/List.pm ↑ Summary lib/WWW/Hetzner/CLI/Cmd/PrimaryIp/Cmd/Describe.pm »