« lib/WWW/Hetzner/CLI/Cmd/Network/Cmd/Describe.pm
↑ Summary
lib/WWW/Hetzner/CLI/Cmd/FloatingIp/Cmd/Describe.pm »
| 1 | package WWW::Hetzner::CLI::Cmd::Costs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Show the current running cost of the project | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 costs [--label SELECTOR] [--net] [--json]'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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 | option label => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | format => 's', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | short => 'l', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | doc => 'Label selector applied to every resource list (e.g., env=prod)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | option net => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | doc => 'Use net prices instead of gross', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | option json => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | doc => 'Print the result as JSON', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 5 | ▶ | sub execute { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
execute: called CC=19 SCAR=30.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 5 | my ($self, $args, $chain) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 5 | my $main = $chain->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 5 | my $cloud = $main->cloud; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 5 | my %params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 5 | ▶ | $params{label_selector} = $self->label if $self->label; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 5 | ▶ | $params{price} = 'net' if $self->net; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 5 | my $costs = $cloud->costs(%params); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 5 | ▶ | if ($self->json || $main->output eq 'json') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->json or $main->output eq "json"
MC/DC100%2/2
$self->json or $main->output eq "json"
$self->json
$main->output eq "json"
Truth table100%3/3
A or B
A= $self->jsonB= $main->output eq "json"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | print encode_json($costs), "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 3 | ▶ | my $cur = $costs->{currency} // 'EUR'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$costs->{"currency"} // "EUR"
MC/DC0%0/1
$costs->{"currency"} // "EUR"
$costs->{"currency"}
Truth table50%1/2
A
A= $costs->{"currency"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | printf "Prices: %s, %s (VAT %s%%)%s\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | $costs->{price}, $cur, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | defined $costs->{vat_rate} ? 0 + $costs->{vat_rate} : '-', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | defined $costs->{label_selector} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 3 | ▶ | ? ", label selector: $costs->{label_selector}" : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 3 | my $fmt = "%-25s %-14s %-10s %-9s %-11s %11s %12s\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 3 | printf $fmt, 'NAME', 'KIND', 'TYPE', 'LOCATION', 'STATUS', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | "$cur/h", "$cur/month"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 3 | print '-' x 98, "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 3 | for my $r (@{ $costs->{resources} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | printf $fmt, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | $r->{name} // $r->{id} // '-', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | $r->{kind}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | $r->{type} // '-', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | $r->{location} // '-', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | $r->{status} // '-', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | defined $r->{hourly} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ? sprintf('%.4f%s', $r->{hourly}, $r->{hourly_derived} ? '*' : ' ') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | : '? ', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 30 | ▶ | defined $r->{monthly} ? sprintf('%.2f', $r->{monthly}) : '?'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition54%6/11
($r->{"name"} // $r->{"id"}) // "-"
$r->{"name"} // $r->{"id"}
$r->{"type"} // "-"
$r->{"location"} // "-"
$r->{"status"} // "-"
MC/DC0%0/2
($r->{"name"} // $r->{"id"}) // "-"
$r->{"name"}
$r->{"id"}
MC/DC0%0/1
$r->{"type"} // "-"
$r->{"type"}
MC/DC0%0/1
$r->{"location"} // "-"
$r->{"location"}
MC/DC100%1/1
$r->{"status"} // "-"
$r->{"status"}
Truth table33%1/3
A // B
A= $r->{"name"}B= $r->{"id"}
Truth table50%1/2
A
A= $r->{"type"}
Truth table50%1/2
A
A= $r->{"location"}
Truth table100%2/2
A
A= $r->{"status"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 3 | print '-' x 98, "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | printf $fmt, 'TOTAL', '', '', '', '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | sprintf('%.4f ', $costs->{totals}{hourly}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 3 | sprintf('%.2f', $costs->{totals}{monthly}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | print "\n* hourly derived as monthly / $costs->{hours_per_month}h (no hourly price in the price list)\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 3 | ▶ | if grep { $_->{hourly_derived} } @{ $costs->{resources} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 3 | print STDERR "Warning: $_\n" for @{ $costs->{warnings} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||