lib/WWW/Hetzner/Cloud/LoadBalancer.pm

filter: Statementstmt 76.1% 64 / 84 Branchbran 41.1% 14 / 34 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 73.0% 19 / 26 Podpod 100% 14 / 14 totaltotal 68.9% 111 / 161 CC 19 SCAR 12.5
CC
19
Cov
65%
refresh
12.0
update
6.0
delete
6.0
CRAP 3.5
« lib/WWW/Hetzner/CLI/Cmd/StorageBox/Cmd/EnableSnapshotPlan.pm ↑ Summary lib/WWW/Hetzner/CLI/Cmd/StorageBox/Cmd/Subaccount/Cmd/Create.pm »
1 package WWW::Hetzner::Cloud::LoadBalancer;
2 # ABSTRACT: Hetzner Cloud Load Balancer 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 10 ▶has public_net => ( is => 'ro', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
26  
27  
28 10 ▶has private_net => ( is => 'ro', default => sub { [] } );
Subroutine __ANON__: called CC=1 SCAR=0.0
29  
30  
31 0 ▶has location => ( is => 'ro', default => sub { {} } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
32  
33  
34 0 ▶has load_balancer_type => ( is => 'ro', default => sub { {} } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
35  
36  
37 10 ▶has protection => ( is => 'ro', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
38  
39  
40 0 ▶has labels => ( is => 'rw', default => sub { {} } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
41  
42  
43 10 ▶has targets => ( is => 'ro', default => sub { [] } );
Subroutine __ANON__: called CC=1 SCAR=0.0
44  
45  
46 10 ▶has services => ( is => 'ro', default => sub { [] } );
Subroutine __ANON__: called CC=1 SCAR=0.0
47  
48  
49 10 ▶has algorithm => ( is => 'ro', default => sub { {} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
50  
51  
52 60 has created => ( is => 'ro' );
53  
54  
55 60 has outgoing_traffic => ( is => 'ro' );
56  
57  
58 60 has ingoing_traffic => ( is => 'ro' );
59  
60  
61 60 has included_traffic => ( is => 'ro' );
62  
63  
64 # Convenience
65 23 ▶sub location_name { shift->location->{name} }
Subroutine location_name: called CC=1 SCAR=0.0
Pod documented
66  
67  
68 23 ▶sub type_name { shift->load_balancer_type->{name} }
Subroutine type_name: called CC=1 SCAR=0.0
Pod documented
69  
70  
71 3 ▶sub ipv4 { shift->public_net->{ipv4}{ip} }
Subroutine ipv4: called CC=1 SCAR=0.0
Pod documented
72  
73  
74 1 ▶sub ipv6 { shift->public_net->{ipv6}{ip} }
Subroutine ipv6: called CC=1 SCAR=0.0
Pod documented
75  
76  
77 # Actions
78 0 ▶sub update {
Subroutine update: not called CC=2 SCAR=17.9
Pod documented
79 0 my ($self) = @_;
80 0 ▶ croak "Cannot update load balancer without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
81  
82 0 my $result = $self->_client->put("/load_balancers/" . $self->id, {
83 name => $self->name,
84 labels => $self->labels,
85 });
86 0 return $self;
87 }
88  
89  
90 0 ▶sub delete {
Subroutine delete: not called CC=2 SCAR=17.9
Pod documented
91 0 my ($self) = @_;
92 0 ▶ croak "Cannot delete load balancer without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
93  
94 0 $self->_client->delete("/load_balancers/" . $self->id);
95 0 return 1;
96 }
97  
98  
99 1 ▶sub add_target {
Subroutine add_target: called CC=3 SCAR=11.4
Pod documented
100 1 my ($self, %opts) = @_;
101 1 ▶ croak "Cannot modify load balancer without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 1 1
102 1 ▶ croak "type required" unless $opts{type};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"type"} 0 1 1
103  
104 1 return $self->_client->load_balancers->add_target($self->id, %opts);
105 }
106  
107  
108 1 ▶sub remove_target {
Subroutine remove_target: called CC=3 SCAR=11.4
Pod documented
109 1 my ($self, %opts) = @_;
110 1 ▶ croak "Cannot modify load balancer without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 1 1
111 1 ▶ croak "type required" unless $opts{type};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"type"} 0 1 1
112  
113 1 return $self->_client->load_balancers->remove_target($self->id, %opts);
114 }
115  
116  
117 1 ▶sub add_service {
Subroutine add_service: called CC=5 SCAR=17.2
Pod documented
118 1 my ($self, %opts) = @_;
119 1 ▶ croak "Cannot modify load balancer without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 1 1
120 1 ▶ croak "protocol required" unless $opts{protocol};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"protocol"} 0 1 1
121 1 ▶ croak "listen_port required" unless $opts{listen_port};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"listen_port"} 0 1 1
122 1 ▶ croak "destination_port required" unless $opts{destination_port};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"destination_port"} 0 1 1
123  
124 1 return $self->_client->load_balancers->add_service($self->id, %opts);
125 }
126  
127  
128 1 ▶sub delete_service {
Subroutine delete_service: called CC=3 SCAR=11.4
Pod documented
129 1 my ($self, $listen_port) = @_;
130 1 ▶ croak "Cannot modify load balancer without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 1 1
131 1 ▶ croak "listen_port required" unless $listen_port;
Branch: 1 branch
BranchTrueFalseTotal
unless $listen_port 0 1 1
132  
133 1 return $self->_client->load_balancers->delete_service($self->id, $listen_port);
134 }
135  
136  
137 1 ▶sub attach_to_network {
Subroutine attach_to_network: called CC=3 SCAR=11.4
Pod documented
138 1 my ($self, $network_id, %opts) = @_;
139 1 ▶ croak "Cannot modify load balancer without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 1 1
140 1 ▶ croak "network required" unless $network_id;
Branch: 1 branch
BranchTrueFalseTotal
unless $network_id 0 1 1
141  
142 1 return $self->_client->load_balancers->attach_to_network($self->id, $network_id, %opts);
143 }
144  
145  
146 1 ▶sub detach_from_network {
Subroutine detach_from_network: called CC=3 SCAR=11.4
Pod documented
147 1 my ($self, $network_id) = @_;
148 1 ▶ croak "Cannot modify load balancer without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 1 1
149 1 ▶ croak "network required" unless $network_id;
Branch: 1 branch
BranchTrueFalseTotal
unless $network_id 0 1 1
150  
151 1 return $self->_client->load_balancers->detach_from_network($self->id, $network_id);
152 }
153  
154  
155 0 ▶sub refresh {
Subroutine refresh: not called CC=3 SCAR=24.8
Pod documented
156 0 my ($self) = @_;
157 0 ▶ croak "Cannot refresh load balancer without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
158  
159 0 my $result = $self->_client->get("/load_balancers/" . $self->id);
160 0 my $data = $result->{load_balancer};
161  
162 0 $self->name($data->{name});
163 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
164  
165 0 return $self;
166 }
167  
168  
169 0 ▶sub data {
Subroutine data: not called CC=1 SCAR=6.9
Pod documented
170 0 my ($self) = @_;
171 return {
172 0 id => $self->id,
173 name => $self->name,
174 public_net => $self->public_net,
175 private_net => $self->private_net,
176 location => $self->location,
177 load_balancer_type => $self->load_balancer_type,
178 protection => $self->protection,
179 labels => $self->labels,
180 targets => $self->targets,
181 services => $self->services,
182 algorithm => $self->algorithm,
183 created => $self->created,
184 };
185 }
186  
187  
188  
189 60 1.
190  
191 __END__
« lib/WWW/Hetzner/CLI/Cmd/StorageBox/Cmd/EnableSnapshotPlan.pm ↑ Summary lib/WWW/Hetzner/CLI/Cmd/StorageBox/Cmd/Subaccount/Cmd/Create.pm »