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

filter: Statementstmt 94.7% 36 / 38 Branchbran 50.0% 3 / 6 Conditioncond 45.0% 9 / 20 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 66.2% 55 / 83 CC 15 SCAR 18.3
CC
15
Cov
75%
_print_type_prices
9.7
execute
5.6
_gross
5.4
CRAP 6.3
« lib/WWW/Hetzner/Cloud/API/LoadBalancers.pm ↑ Summary lib/WWW/Hetzner/Cloud/API/Certificates.pm »
1 package WWW::Hetzner::CLI::Cmd::Pricing;
2 # ABSTRACT: Pricing 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 pricing [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 6 ▶sub _gross {
Subroutine _gross: called CC=4 SCAR=16.9
13 6 my ($price) = @_;
14 6 ▶ return defined $price && ref $price eq 'HASH' ? ($price->{gross} // '-') : '-';
Branch: 1 branch
BranchTrueFalseTotal
defined $price && ref $price eq 'HASH' ? : 6 0 6
Condition40%2/5
defined $price and ref $price eq "HASH"
!ll&&!rl&&r
006
$price->{"gross"} // "-"
l!l
60
MC/DC0%0/2
defined $price and ref $price eq "HASH"
defined $price ref $price eq "HASH"
MC/DC0%0/1
$price->{"gross"} // "-"
$price->{"gross"}
Truth table33%1/3
A and B
A= defined $priceB= ref $price eq "HASH"
ABresult
0X0
100
111
Truth table50%1/2
A
A= $price->{"gross"}
Aresult
11
00
15 }
16  
17 1 ▶sub execute {
Subroutine execute: called CC=5 SCAR=17.2
Pod undocumented
18 1 my ($self, $args, $chain) = @_;
19  
20 1 my $main = $chain->[0];
21 1 my $cloud = $main->cloud;
22  
23 1 my $pricing = $cloud->pricing->get;
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($pricing->data), "\n";
27 0 return;
28 }
29  
30 1 ▶ printf "Currency: %s (VAT %s%%)\n",
Condition50%2/4
$pricing->currency // "-"
l!l
10
$pricing->vat_rate // "-"
l!l
10
MC/DC0%0/1
$pricing->currency // "-"
$pricing->currency
MC/DC0%0/1
$pricing->vat_rate // "-"
$pricing->vat_rate
Truth table50%1/2
A
A= $pricing->currency
Aresult
11
00
Truth table50%1/2
A
A= $pricing->vat_rate
Aresult
11
00
31 $pricing->currency // '-', $pricing->vat_rate // '-';
32 printf "Image: %s per GB/month\n",
33 1 _gross($pricing->image->{price_per_gb_month});
34 printf "Volume: %s per GB/month\n",
35 1 _gross($pricing->volume->{price_per_gb_month});
36 printf "Server backup: %s%% of the server price\n",
37 1 ▶ $pricing->server_backup->{percentage} // '-';
Condition50%1/2
$pricing->server_backup->{"percentage"} // "-"
l!l
10
MC/DC0%0/1
$pricing->server_backup->{"percentage"} // "-"
$pricing->server_backup->{"percentage"}
Truth table50%1/2
A
A= $pricing->server_backup->{"percentage"}
Aresult
11
00
38  
39 1 _print_type_prices('SERVER TYPES', $pricing->server_types);
40 1 _print_type_prices('LOAD BALANCER TYPES', $pricing->load_balancer_types);
41 }
42  
43 2 ▶sub _print_type_prices {
Subroutine _print_type_prices: called CC=8 SCAR=22.8
44 2 my ($title, $types) = @_;
45  
46 2 ▶ return unless $types && @$types;
Branch: 1 branch
BranchTrueFalseTotal
unless $types and @$types 0 2 2
Condition33%1/3
$types and @$types
!ll&&!rl&&r
002
MC/DC0%0/2
$types and @$types
$types @$types
Truth table33%1/3
A and B
A= $typesB= @$types
ABresult
0X0
100
111
47  
48 2 printf "\n%s\n", $title;
49 2 printf "%-12s %-10s %-12s %s\n", 'NAME', 'LOCATION', 'HOURLY', 'MONTHLY';
50 2 printf "%-12s %-10s %-12s %s\n", '-' x 12, '-' x 10, '-' x 12, '-' x 12;
51  
52 2 for my $type (@$types) {
53 2 ▶ for my $price (@{ $type->{prices} // [] }) {
Condition50%1/2
$type->{"prices"} // []
l!l
20
MC/DC0%0/1
$type->{"prices"} // []
$type->{"prices"}
Truth table50%1/2
A
A= $type->{"prices"}
Aresult
11
00
54 printf "%-12s %-10s %-12s %s\n",
55 $type->{name} // '-',
56 $price->{location} // '-',
57 _gross($price->{price_hourly}),
58 2 ▶ _gross($price->{price_monthly});
Condition50%2/4
$type->{"name"} // "-"
l!l
20
$price->{"location"} // "-"
l!l
20
MC/DC0%0/1
$type->{"name"} // "-"
$type->{"name"}
MC/DC0%0/1
$price->{"location"} // "-"
$price->{"location"}
Truth table50%1/2
A
A= $type->{"name"}
Aresult
11
00
Truth table50%1/2
A
A= $price->{"location"}
Aresult
11
00
59 }
60 }
61 }
62  
63 1 1;
64  
65 __END__
« lib/WWW/Hetzner/Cloud/API/LoadBalancers.pm ↑ Summary lib/WWW/Hetzner/Cloud/API/Certificates.pm »