lib/WWW/Hetzner/Cloud/API/Locations.pm

filter: Statementstmt 96.9% 32 / 33 Branchbran 66.6% 4 / 6 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 9 / 9 Podpod 100% 3 / 3 totaltotal 90.7% 49 / 54 CC 6 SCAR 7.8
CC
6
Cov
90%
get_by_name
4.1
list
2.0
get
2.0
CRAP 2.2
« lib/WWW/Hetzner/Robot/API/Servers.pm ↑ Summary lib/WWW/Hetzner/Cloud/API/Datacenters.pm »
1 package WWW::Hetzner::Cloud::API::Locations;
2 # ABSTRACT: Hetzner Cloud Locations API
3  
4 25 our $VERSION = '0.100';
5  
6 25 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 25 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 25 ▶use WWW::Hetzner::Cloud::Location;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 25 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12 25 has client => (
13 is => 'ro',
14 required => 1,
15 weak_ref => 1,
16 );
17  
18 sub _wrap {
19 7 ▶ my ($self, $data) = @_;
Subroutine _wrap: called CC=1 SCAR=0.0
20 7 return WWW::Hetzner::Cloud::Location->new(
21 client => $self->client,
22 %$data,
23 );
24 }
25  
26 sub _wrap_list {
27 2 ▶ my ($self, $list) = @_;
Subroutine _wrap_list: called CC=1 SCAR=0.0
28 2 return [ map { $self->_wrap($_) } @$list ];
29 }
30  
31  
32 sub list {
33 2 ▶ my ($self, %params) = @_;
Subroutine list: called CC=2 SCAR=7.1
Pod documented
34  
35 2 my $result = $self->client->get('/locations', params => \%params);
36 2 ▶ return $self->_wrap_list($result->{locations} // []);
Condition50%1/2
$result->{"locations"} // []
l!l
20
MC/DC0%0/1
$result->{"locations"} // []
$result->{"locations"}
Truth table50%1/2
A
A= $result->{"locations"}
Aresult
11
00
37 }
38  
39  
40 sub get {
41 1 ▶ my ($self, $id) = @_;
Subroutine get: called CC=2 SCAR=7.0
Pod documented
42 1 ▶ croak "Location ID required" unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 1 1
43  
44 1 my $result = $self->client->get("/locations/$id");
45 1 return $self->_wrap($result->{location});
46 }
47  
48  
49 sub get_by_name {
50 1 ▶ my ($self, $name) = @_;
Subroutine get_by_name: called CC=4 SCAR=14.2
Pod documented
51 1 ▶ croak "Name required" unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 1 1
52  
53 1 my $locations = $self->list;
54 1 for my $loc (@$locations) {
55 2 ▶ return $loc if $loc->name eq $name;
Branch: 1 branch
BranchTrueFalseTotal
if $loc->name eq $name 1 1 2
56 }
57 0 return;
58 }
59  
60  
61 25 1;
62  
63 __END__
« lib/WWW/Hetzner/Robot/API/Servers.pm ↑ Summary lib/WWW/Hetzner/Cloud/API/Datacenters.pm »