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

filter: Statementstmt 79.0% 49 / 62 Branchbran 42.1% 16 / 38 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 85.7% 12 / 14 Podpod 100% 8 / 8 totaltotal 67.9% 87 / 128 CC 22 SCAR 22.6
CC
22
Cov
64%
update
30.0
change_dns_ptr
20.0
create
8.1
CRAP 9.6
« lib/WWW/Hetzner/Cloud/API/LoadBalancers.pm ↑ Summary lib/WWW/Hetzner/Cloud/PrimaryIP.pm »
1 package WWW::Hetzner::Cloud::API::PrimaryIPs;
2 # ABSTRACT: Hetzner Cloud Primary IPs 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::PrimaryIP;
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 4 ▶ my ($self, $data) = @_;
Subroutine _wrap: called CC=1 SCAR=0.0
20 4 return WWW::Hetzner::Cloud::PrimaryIP->new(
21 client => $self->client,
22 %$data,
23 );
24 }
25  
26 sub _wrap_list {
27 1 ▶ my ($self, $list) = @_;
Subroutine _wrap_list: called CC=1 SCAR=0.0
28 1 return [ map { $self->_wrap($_) } @$list ];
29 }
30  
31  
32 sub list {
33 1 ▶ my ($self, %params) = @_;
Subroutine list: called CC=2 SCAR=7.1
Pod documented
34  
35 1 my $result = $self->client->get('/primary_ips', params => \%params);
36 1 ▶ return $self->_wrap_list($result->{primary_ips} // []);
Condition50%1/2
$result->{"primary_ips"} // []
l!l
10
MC/DC0%0/1
$result->{"primary_ips"} // []
$result->{"primary_ips"}
Truth table50%1/2
A
A= $result->{"primary_ips"}
Aresult
11
00
37 }
38  
39  
40 sub get {
41 2 ▶ my ($self, $id) = @_;
Subroutine get: called CC=2 SCAR=7.0
Pod documented
42 2 ▶ croak "Primary IP ID required" unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 2 2
43  
44 2 my $result = $self->client->get("/primary_ips/$id");
45 2 return $self->_wrap($result->{primary_ip});
46 }
47  
48  
49 sub create {
50 5 ▶ my ($self, %params) = @_;
Subroutine create: called CC=8 SCAR=20.9
Pod documented
51  
52 5 ▶ croak "name required" unless $params{name};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"name"} 1 4 5
53 4 ▶ croak "type required (ipv4 or ipv6)" unless $params{type};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"type"} 1 3 4
54 3 ▶ croak "assignee_type required" unless $params{assignee_type};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"assignee_type"} 1 2 3
55 2 ▶ croak "datacenter required" unless $params{datacenter};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"datacenter"} 1 1 2
56  
57 my $body = {
58 name => $params{name},
59 type => $params{type},
60 assignee_type => $params{assignee_type},
61 datacenter => $params{datacenter},
62 1 };
63  
64 1 ▶ $body->{assignee_id} = $params{assignee_id} if $params{assignee_id};
Branch: 1 branch
BranchTrueFalseTotal
if $params{"assignee_id"} 0 1 1
65 1 ▶ $body->{auto_delete} = $params{auto_delete} if exists $params{auto_delete};
Branch: 1 branch
BranchTrueFalseTotal
if exists $params{"auto_delete"} 0 1 1
66 1 ▶ $body->{labels} = $params{labels} if $params{labels};
Branch: 1 branch
BranchTrueFalseTotal
if $params{"labels"} 0 1 1
67  
68 1 my $result = $self->client->post('/primary_ips', $body);
69 1 return $self->_wrap($result->{primary_ip});
70 }
71  
72  
73 sub update {
74 0 ▶ my ($self, $id, %params) = @_;
Subroutine update: not called CC=5 SCAR=34.0
Pod documented
75 0 ▶ croak "Primary IP ID required" unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 0 0
76  
77 0 my $body = {};
78 0 ▶ $body->{name} = $params{name} if exists $params{name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $params{"name"} 0 0 0
79 0 ▶ $body->{auto_delete} = $params{auto_delete} if exists $params{auto_delete};
Branch: 1 branch
BranchTrueFalseTotal
if exists $params{"auto_delete"} 0 0 0
80 0 ▶ $body->{labels} = $params{labels} if exists $params{labels};
Branch: 1 branch
BranchTrueFalseTotal
if exists $params{"labels"} 0 0 0
81  
82 0 my $result = $self->client->put("/primary_ips/$id", $body);
83 0 return $self->_wrap($result->{primary_ip});
84 }
85  
86  
87 sub delete {
88 1 ▶ my ($self, $id) = @_;
Subroutine delete: called CC=2 SCAR=7.1
Pod documented
89 1 ▶ croak "Primary IP ID required" unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 1 1
90  
91 1 return $self->client->delete("/primary_ips/$id");
92 }
93  
94  
95 sub assign {
96 1 ▶ my ($self, $id, $assignee_id, $assignee_type) = @_;
Subroutine assign: called CC=4 SCAR=14.6
Pod documented
97 1 ▶ croak "Primary IP ID required" unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 1 1
98 1 ▶ croak "Assignee ID required" unless $assignee_id;
Branch: 1 branch
BranchTrueFalseTotal
unless $assignee_id 0 1 1
99 1 ▶ $assignee_type //= 'server';
Condition50%1/2
$assignee_type //= "server"
l!l
10
MC/DC0%0/1
$assignee_type //= "server"
$assignee_type
Truth table50%1/2
A
A= $assignee_type
Aresult
11
00
100  
101 1 return $self->client->post("/primary_ips/$id/actions/assign", {
102 assignee_id => $assignee_id,
103 assignee_type => $assignee_type,
104 });
105 }
106  
107  
108 sub unassign {
109 1 ▶ my ($self, $id) = @_;
Subroutine unassign: called CC=2 SCAR=7.1
Pod documented
110 1 ▶ croak "Primary IP ID required" unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 1 1
111  
112 1 return $self->client->post("/primary_ips/$id/actions/unassign", {});
113 }
114  
115  
116 sub change_dns_ptr {
117 0 ▶ my ($self, $id, $ip, $dns_ptr) = @_;
Subroutine change_dns_ptr: not called CC=4 SCAR=30.0
Pod documented
118 0 ▶ croak "Primary IP ID required" unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 0 0
119 0 ▶ croak "IP required" unless $ip;
Branch: 1 branch
BranchTrueFalseTotal
unless $ip 0 0 0
120 0 ▶ croak "dns_ptr required" unless defined $dns_ptr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dns_ptr 0 0 0
121  
122 0 return $self->client->post("/primary_ips/$id/actions/change_dns_ptr", {
123 ip => $ip,
124 dns_ptr => $dns_ptr,
125 });
126 }
127  
128  
129 25 1;
130  
131 __END__
« lib/WWW/Hetzner/Cloud/API/LoadBalancers.pm ↑ Summary lib/WWW/Hetzner/Cloud/PrimaryIP.pm »