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

filter: Statementstmt 94.2% 33 / 35 Branchbran 50.0% 5 / 10 Conditioncond 40.0% 4 / 10 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 71.2% 47 / 66 CC 11 SCAR 24.1
CC
11
Cov
76%
execute
14.9
BEGIN
1.0
BEGIN
1.0
CRAP 11.2
« lib/WWW/Hetzner/CLI/Cmd/Iso.pm ↑ Summary lib/WWW/Hetzner/Robot/CLI/Cmd/Failover.pm »
1 package WWW::Hetzner::CLI::Cmd::StorageBox::Cmd::AddLabel;
2 # ABSTRACT: Add a label to a Storage Box
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: hcloud.pl storage-box add-label <storage-box> <key>=<value>';
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 ▶sub execute {
Subroutine execute: called CC=11 SCAR=27.0
Pod undocumented
13 1 my ($self, $args, $chain) = @_;
14 1 ▶ my $id = $args->[0] or die "Usage: hcloud.pl storage-box add-label <storage-box> <key>=<value>\n";
Branch: 1 branch
BranchTrueFalseTotal
my $id = $args->[0] or die "Usage: hcloud.pl storage-box add-label <storage-box> <key>=<value>\n" 1 0 1
15 1 ▶ my $label = $args->[1] or die "Usage: hcloud.pl storage-box add-label <storage-box> <key>=<value>\n";
Branch: 1 branch
BranchTrueFalseTotal
my $label = $args->[1] or die "Usage: hcloud.pl storage-box add-label <storage-box> <key>=<value>\n" 1 0 1
16 1 my ($key, $value) = split /=/, $label, 2;
17 1 ▶ die "Label must be key=value\n" unless defined $key && length $key && defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key and length $key and defined $value 0 1 1
Condition33%2/6
defined $key and length $key and defined $value
!ll&&!rl&&r
001
defined $key and length $key
!ll&&!rl&&r
001
MC/DC0%0/3
defined $key and length $key and defined $value
defined $key length $key defined $value
Truth table25%1/4
A and B and C
A= defined $keyB= length $keyC= defined $value
ABCresult
0XX0
10X0
1100
1111
18  
19 1 my $main = $chain->[0];
20 1 my $box = $main->storage->storage_boxes->get($id);
21 1 ▶ my %labels = %{ $box->labels // {} };
Condition50%1/2
$box->labels // {}
l!l
10
MC/DC0%0/1
$box->labels // {}
$box->labels
Truth table50%1/2
A
A= $box->labels
Aresult
11
00
22 1 $labels{$key} = $value;
23 1 my $updated = $main->storage->storage_boxes->update($id, labels => \%labels);
24  
25 1 ▶ if ($main->output eq 'json') {
Branch: 1 branch
BranchTrueFalseTotal
if ($main->output eq "json") 0 1 1
26 0 print encode_json($updated->data), "\n";
27 0 return;
28 }
29  
30 1 print "Storage Box labels updated:\n";
31 1 printf " ID: %s\n", $updated->id;
32 1 printf " Name: %s\n", $updated->name;
33 1 ▶ my $new_labels = $updated->labels // {};
Condition50%1/2
$updated->labels // {}
l!l
10
MC/DC0%0/1
$updated->labels // {}
$updated->labels
Truth table50%1/2
A
A= $updated->labels
Aresult
11
00
34 1 ▶ if (%$new_labels) {
Branch: 1 branch
BranchTrueFalseTotal
if (%$new_labels) 1 0 1
35 1 print " Labels:\n";
36 1 printf " %s: %s\n", $_, $new_labels->{$_} for sort keys %$new_labels;
37 }
38 }
39  
40 1 1;
41  
42 __END__
« lib/WWW/Hetzner/CLI/Cmd/Iso.pm ↑ Summary lib/WWW/Hetzner/Robot/CLI/Cmd/Failover.pm »