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

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