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

filter: Statementstmt 95.0% 38 / 40 Branchbran 50.0% 6 / 12 Conditioncond 41.6% 5 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 71.4% 55 / 77 CC 13 SCAR 26.1
CC
13
Cov
77%
execute
18.5
BEGIN
1.0
BEGIN
1.0
CRAP 13.6
« lib/WWW/Hetzner/CLI/Cmd/StorageBox/Cmd/Subaccount/Cmd/List.pm ↑ Summary lib/WWW/Hetzner/CLI/Cmd/StorageBox/Cmd/Subaccount.pm »
1 package WWW::Hetzner::CLI::Cmd::StorageBox::Cmd::Snapshot::Cmd::AddLabel;
2 # ABSTRACT: Add a label to a Storage Box snapshot
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 snapshot add-label <storage-box> <snapshot> <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 1 ▶use WWW::Hetzner::Storage::API::Snapshots;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 1 ▶sub execute {
Subroutine execute: called CC=13 SCAR=29.2
Pod undocumented
14 1 my ($self, $args, $chain) = @_;
15 1 ▶ my $id = $args->[0] or die "Usage: hcloud.pl storage-box snapshot add-label <storage-box> <snapshot> <key>=<value>\n";
Branch: 1 branch
BranchTrueFalseTotal
my $id = $args->[0] or die "Usage: hcloud.pl storage-box snapshot add-label <storage-box> <snapshot> <key>=<value>\n" 1 0 1
16 1 ▶ my $snap = $args->[1] or die "Usage: hcloud.pl storage-box snapshot add-label <storage-box> <snapshot> <key>=<value>\n";
Branch: 1 branch
BranchTrueFalseTotal
my $snap = $args->[1] or die "Usage: hcloud.pl storage-box snapshot add-label <storage-box> <snapshot> <key>=<value>\n" 1 0 1
17 1 ▶ my $label = $args->[2] or die "Usage: hcloud.pl storage-box snapshot add-label <storage-box> <snapshot> <key>=<value>\n";
Branch: 1 branch
BranchTrueFalseTotal
my $label = $args->[2] or die "Usage: hcloud.pl storage-box snapshot add-label <storage-box> <snapshot> <key>=<value>\n" 1 0 1
18 1 my ($key, $value) = split /=/, $label, 2;
19 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
20  
21 1 my $main = $chain->[0];
22 1 my $snapshots = WWW::Hetzner::Storage::API::Snapshots->new(
23 client => $main->storage,
24 storage_box_id => $id,
25 );
26 1 my $snapshot = $snapshots->get($snap);
27 1 ▶ my %labels = %{ $snapshot->labels // {} };
Condition50%1/2
$snapshot->labels // {}
l!l
10
MC/DC0%0/1
$snapshot->labels // {}
$snapshot->labels
Truth table50%1/2
A
A= $snapshot->labels
Aresult
11
00
28 1 $labels{$key} = $value;
29 1 my $updated = $snapshots->update($snap, labels => \%labels);
30  
31 1 ▶ if ($main->output eq 'json') {
Branch: 1 branch
BranchTrueFalseTotal
if ($main->output eq "json") 0 1 1
32 0 print encode_json($updated->data), "\n";
33 0 return;
34 }
35  
36 1 print "Snapshot labels updated:\n";
37 1 printf " ID: %s\n", $updated->id;
38 1 ▶ printf " Name: %s\n", $updated->name // '-';
Condition50%1/2
$updated->name // "-"
l!l
10
MC/DC0%0/1
$updated->name // "-"
$updated->name
Truth table50%1/2
A
A= $updated->name
Aresult
11
00
39 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
40 1 ▶ if (%$new_labels) {
Branch: 1 branch
BranchTrueFalseTotal
if (%$new_labels) 1 0 1
41 1 print " Labels:\n";
42 1 printf " %s: %s\n", $_, $new_labels->{$_} for sort keys %$new_labels;
43 }
44 }
45  
46 1 1;
47  
48 __END__
« lib/WWW/Hetzner/CLI/Cmd/StorageBox/Cmd/Subaccount/Cmd/List.pm ↑ Summary lib/WWW/Hetzner/CLI/Cmd/StorageBox/Cmd/Subaccount.pm »