lib/WWW/Hetzner/Cloud/PrimaryIP.pm

filter: Statementstmt 74.6% 50 / 67 Branchbran 33.3% 6 / 18 Conditioncond 57.1% 4 / 7 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 77.7% 14 / 18 Podpod 100% 10 / 10 totaltotal 69.3% 86 / 124 CC 13 SCAR 13.3
CC
13
Cov
65%
refresh
12.0
update
6.0
delete
6.0
CRAP 3.8
« lib/WWW/Hetzner/Cloud/Volume.pm ↑ Summary lib/WWW/Hetzner/Cloud/API/Volumes.pm »
1 package WWW::Hetzner::Cloud::PrimaryIP;
2 # ABSTRACT: Hetzner Cloud Primary IP object
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::HasAction';
8 60 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 60 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12 60 has _client => (
13 is => 'ro',
14 required => 1,
15 weak_ref => 1,
16 init_arg => 'client',
17 );
18  
19 60 has id => ( is => 'ro' );
20  
21  
22 60 has name => ( is => 'rw' );
23  
24  
25 60 has ip => ( is => 'ro' );
26  
27  
28 60 has type => ( is => 'ro' );
29  
30  
31 60 has assignee_id => ( is => 'ro' );
32  
33  
34 60 has assignee_type => ( is => 'ro' );
35  
36  
37 34 ▶has datacenter => ( is => 'ro', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
38  
39  
40 9 ▶has location_data => ( is => 'ro', init_arg => 'location', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
41  
42 33 ▶has dns_ptr => ( is => 'ro', default => sub { [] } );
Subroutine __ANON__: called CC=1 SCAR=0.0
43  
44  
45 60 has auto_delete => ( is => 'rw' );
46  
47  
48 60 has blocked => ( is => 'ro' );
49  
50  
51 0 ▶has labels => ( is => 'rw', default => sub { {} } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
52  
53  
54 33 ▶has protection => ( is => 'ro', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
55  
56  
57 60 has created => ( is => 'ro' );
58  
59  
60 # Convenience
61 32 ▶sub is_assigned { defined shift->assignee_id }
Subroutine is_assigned: called CC=1 SCAR=0.0
Pod documented
62  
63  
64 2 ▶sub datacenter_name { shift->datacenter->{name} }
Subroutine datacenter_name: called CC=1 SCAR=0.0
Pod documented
65  
66  
67 55 ▶sub location {
Subroutine location: called CC=2 SCAR=6.9
Pod documented
68 55 my ($self) = @_;
69 55 ▶ return $self->location_data->{name} // $self->datacenter->{location}{name};
Condition100%3/3
$self->location_data->{"name"} // $self->datacenter->{"location"}{"name"}
l!l&&r!l&&!r
5212
MC/DC100%2/2
$self->location_data->{"name"} // $self->datacenter->{"location"}{"name"}
$self->location_data->{"name"} $self->datacenter->{"location"}{"name"}
Truth table100%3/3
A // B
A= $self->location_data->{"name"}B= $self->datacenter->{"location"}{"name"}
ABresult
1X1
011
000
70 }
71  
72  
73 # Actions
74 0 ▶sub update {
Subroutine update: not called CC=2 SCAR=17.9
Pod documented
75 0 my ($self) = @_;
76 0 ▶ croak "Cannot update primary IP without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
77  
78 0 my $result = $self->_client->put("/primary_ips/" . $self->id, {
79 name => $self->name,
80 auto_delete => $self->auto_delete,
81 labels => $self->labels,
82 });
83 0 return $self;
84 }
85  
86  
87 0 ▶sub delete {
Subroutine delete: not called CC=2 SCAR=17.9
Pod documented
88 0 my ($self) = @_;
89 0 ▶ croak "Cannot delete primary IP without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
90  
91 0 $self->_client->delete("/primary_ips/" . $self->id);
92 0 return 1;
93 }
94  
95  
96 1 ▶sub assign {
Subroutine assign: called CC=4 SCAR=14.6
Pod documented
97 1 my ($self, $assignee_id, $assignee_type) = @_;
98 1 ▶ croak "Cannot assign primary IP without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 1 1
99 1 ▶ croak "Assignee ID required" unless $assignee_id;
Branch: 1 branch
BranchTrueFalseTotal
unless $assignee_id 0 1 1
100 1 ▶ $assignee_type //= 'server';
Condition50%1/2
$assignee_type //= "server"
l!l
01
MC/DC0%0/1
$assignee_type //= "server"
$assignee_type
Truth table50%1/2
A
A= $assignee_type
Aresult
11
00
101  
102 1 return $self->_client->primary_ips->assign($self->id, $assignee_id, $assignee_type);
103 }
104  
105  
106 1 ▶sub unassign {
Subroutine unassign: called CC=2 SCAR=7.1
Pod documented
107 1 my ($self) = @_;
108 1 ▶ croak "Cannot unassign primary IP without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 1 1
109  
110 1 return $self->_client->primary_ips->unassign($self->id);
111 }
112  
113  
114 1 ▶sub change_dns_ptr {
Subroutine change_dns_ptr: called CC=4 SCAR=14.6
Pod documented
115 1 my ($self, $ip, $dns_ptr) = @_;
116 1 ▶ croak "Cannot modify primary IP without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 1 1
117 1 ▶ croak "IP required" unless $ip;
Branch: 1 branch
BranchTrueFalseTotal
unless $ip 0 1 1
118 1 ▶ croak "dns_ptr required" unless defined $dns_ptr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dns_ptr 0 1 1
119  
120 1 return $self->_client->primary_ips->change_dns_ptr($self->id, $ip, $dns_ptr);
121 }
122  
123  
124 0 ▶sub refresh {
Subroutine refresh: not called CC=3 SCAR=24.8
Pod documented
125 0 my ($self) = @_;
126 0 ▶ croak "Cannot refresh primary IP without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
127  
128 0 my $result = $self->_client->get("/primary_ips/" . $self->id);
129 0 my $data = $result->{primary_ip};
130  
131 0 $self->name($data->{name});
132 0 $self->auto_delete($data->{auto_delete});
133 0 ▶ $self->labels($data->{labels} // {});
Condition0%0/2
$data->{"labels"} // {}
l!l
00
MC/DC0%0/1
$data->{"labels"} // {}
$data->{"labels"}
Truth table0%0/2
A
A= $data->{"labels"}
Aresult
11
00
134  
135 0 return $self;
136 }
137  
138  
139 2 ▶sub data {
Subroutine data: called CC=1 SCAR=0.0
Pod documented
140 2 my ($self) = @_;
141 return {
142 2 id => $self->id,
143 name => $self->name,
144 ip => $self->ip,
145 type => $self->type,
146 assignee_id => $self->assignee_id,
147 assignee_type => $self->assignee_type,
148 datacenter => $self->datacenter,
149 location => $self->location_data,
150 dns_ptr => $self->dns_ptr,
151 auto_delete => $self->auto_delete,
152 blocked => $self->blocked,
153 labels => $self->labels,
154 protection => $self->protection,
155 created => $self->created,
156 };
157 }
158  
159  
160  
161 60 1.
162  
163 __END__
« lib/WWW/Hetzner/Cloud/Volume.pm ↑ Summary lib/WWW/Hetzner/Cloud/API/Volumes.pm »