| 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
Condition40%2/5
defined $price and ref $price eq "HASH"
$price->{"gross"} // "-"
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"
Truth table50%1/2
A
A= $price->{"gross"}
| |||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||
| 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 // "-"
$pricing->vat_rate // "-"
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
Truth table50%1/2
A
A= $pricing->vat_rate
| |||||||||||||||||||||||||||||||||||||||
| 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"} // "-"
MC/DC0%0/1
$pricing->server_backup->{"percentage"} // "-"
$pricing->server_backup->{"percentage"}
Truth table50%1/2
A
A= $pricing->server_backup->{"percentage"}
| |||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$types and @$types
MC/DC0%0/2
$types and @$types
$types
@$types
Truth table33%1/3
A and B
A= $typesB= @$types
| |||||||||||||||||||||||||||||||||||||||
| 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"} // []
MC/DC0%0/1
$type->{"prices"} // []
$type->{"prices"}
Truth table50%1/2
A
A= $type->{"prices"}
| |||||||||||||||||||||||||||||||||||||||
| 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"} // "-"
$price->{"location"} // "-"
MC/DC0%0/1
$type->{"name"} // "-"
$type->{"name"}
MC/DC0%0/1
$price->{"location"} // "-"
$price->{"location"}
Truth table50%1/2
A
A= $type->{"name"}
Truth table50%1/2
A
A= $price->{"location"}
| |||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||
| 63 | 1 | 1; | |||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||
| 65 | __END__ | ||||||||||||||||||||||||||||||||||||||