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

filter: Statementstmt 92.3% 36 / 39 Branchbran 50.0% 5 / 10 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 1 totaltotal 76.9% 50 / 65 CC 10 SCAR 21.5
CC
10
Cov
80%
execute
12.4
BEGIN
1.0
BEGIN
1.0
CRAP 8.6
« lib/WWW/Hetzner/CLI/Cmd/LoadBalancer/Cmd/List.pm ↑ Summary lib/WWW/Hetzner/CLI/Cmd/StorageBox/Cmd/Snapshot.pm »
1 package WWW::Hetzner::CLI::Cmd::StorageBox::Cmd::Snapshot::Cmd::RemoveLabel;
2 # ABSTRACT: Remove a label from 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 remove-label <storage-box> <snapshot> <key>';
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=10 SCAR=25.2
Pod undocumented
14 1 my ($self, $args, $chain) = @_;
15 1 ▶ my $id = $args->[0] or die "Usage: hcloud.pl storage-box snapshot remove-label <storage-box> <snapshot> <key>\n";
Branch: 1 branch
BranchTrueFalseTotal
my $id = $args->[0] or die "Usage: hcloud.pl storage-box snapshot remove-label <storage-box> <snapshot> <key>\n" 1 0 1
16 1 ▶ my $snap = $args->[1] or die "Usage: hcloud.pl storage-box snapshot remove-label <storage-box> <snapshot> <key>\n";
Branch: 1 branch
BranchTrueFalseTotal
my $snap = $args->[1] or die "Usage: hcloud.pl storage-box snapshot remove-label <storage-box> <snapshot> <key>\n" 1 0 1
17 1 ▶ my $key = $args->[2] or die "Usage: hcloud.pl storage-box snapshot remove-label <storage-box> <snapshot> <key>\n";
Branch: 1 branch
BranchTrueFalseTotal
my $key = $args->[2] or die "Usage: hcloud.pl storage-box snapshot remove-label <storage-box> <snapshot> <key>\n" 1 0 1
18  
19 1 my $main = $chain->[0];
20 1 my $snapshots = WWW::Hetzner::Storage::API::Snapshots->new(
21 client => $main->storage,
22 storage_box_id => $id,
23 );
24 1 my $snapshot = $snapshots->get($snap);
25 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
26 1 delete $labels{$key};
27 1 my $updated = $snapshots->update($snap, labels => \%labels);
28  
29 1 ▶ if ($main->output eq 'json') {
Branch: 1 branch
BranchTrueFalseTotal
if ($main->output eq "json") 0 1 1
30 0 print encode_json($updated->data), "\n";
31 0 return;
32 }
33  
34 1 print "Snapshot labels updated:\n";
35 1 printf " ID: %s\n", $updated->id;
36 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
37 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
38 1 ▶ if (%$new_labels) {
Branch: 1 branch
BranchTrueFalseTotal
if (%$new_labels) { } 1 0 1
39 1 print " Labels:\n";
40 1 printf " %s: %s\n", $_, $new_labels->{$_} for sort keys %$new_labels;
41 } else {
42 0 print " Labels: (none)\n";
43 }
44 }
45  
46 1 1;
47  
48 __END__
« lib/WWW/Hetzner/CLI/Cmd/LoadBalancer/Cmd/List.pm ↑ Summary lib/WWW/Hetzner/CLI/Cmd/StorageBox/Cmd/Snapshot.pm »