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

filter: Statementstmt 89.8% 62 / 69 Branchbran 47.9% 23 / 48 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 93.3% 14 / 15 Podpod 100% 9 / 9 totaltotal 75.6% 109 / 144 CC 26 SCAR 17.7
CC
26
Cov
72%
update
20.0
create
7.3
add_subnet
6.8
CRAP 5.8
« lib/WWW/Hetzner/Robot/CLI/Cmd/Server/Cmd/Describe.pm ↑ Summary lib/WWW/Hetzner/CLI/Cmd/Volume.pm »
1 package WWW::Hetzner::Cloud::API::Networks;
2 # ABSTRACT: Hetzner Cloud Networks 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::Network;
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::Network->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('/networks', params => \%params);
36 1 ▶ return $self->_wrap_list($result->{networks} // []);
Condition50%1/2
$result->{"networks"} // []
l!l
10
MC/DC0%0/1
$result->{"networks"} // []
$result->{"networks"}
Truth table50%1/2
A
A= $result->{"networks"}
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 "Network ID required" unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 2 2
43  
44 2 my $result = $self->client->get("/networks/$id");
45 2 return $self->_wrap($result->{network});
46 }
47  
48  
49 sub create {
50 3 ▶ my ($self, %params) = @_;
Subroutine create: called CC=7 SCAR=19.9
Pod documented
51  
52 3 ▶ croak "name required" unless $params{name};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"name"} 1 2 3
53 2 ▶ croak "ip_range required" unless $params{ip_range};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"ip_range"} 1 1 2
54  
55 my $body = {
56 name => $params{name},
57 ip_range => $params{ip_range},
58 1 };
59  
60 1 ▶ $body->{labels} = $params{labels} if $params{labels};
Branch: 1 branch
BranchTrueFalseTotal
if $params{"labels"} 0 1 1
61 1 ▶ $body->{subnets} = $params{subnets} if $params{subnets};
Branch: 1 branch
BranchTrueFalseTotal
if $params{"subnets"} 0 1 1
62 1 ▶ $body->{routes} = $params{routes} if $params{routes};
Branch: 1 branch
BranchTrueFalseTotal
if $params{"routes"} 0 1 1
63 $body->{expose_routes_to_vswitch} = $params{expose_routes_to_vswitch}
64 1 ▶ if exists $params{expose_routes_to_vswitch};
Branch: 1 branch
BranchTrueFalseTotal
if exists $params{"expose_routes_to_vswitch"} 0 1 1
65  
66 1 my $result = $self->client->post('/networks', $body);
67 1 return $self->_wrap($result->{network});
68 }
69  
70  
71 sub update {
72 0 ▶ my ($self, $id, %params) = @_;
Subroutine update: not called CC=4 SCAR=30.0
Pod documented
73 0 ▶ croak "Network ID required" unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 0 0
74  
75 0 my $body = {};
76 0 ▶ $body->{name} = $params{name} if exists $params{name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $params{"name"} 0 0 0
77 0 ▶ $body->{labels} = $params{labels} if exists $params{labels};
Branch: 1 branch
BranchTrueFalseTotal
if exists $params{"labels"} 0 0 0
78  
79 0 my $result = $self->client->put("/networks/$id", $body);
80 0 return $self->_wrap($result->{network});
81 }
82  
83  
84 sub delete {
85 1 ▶ my ($self, $id) = @_;
Subroutine delete: called CC=2 SCAR=7.1
Pod documented
86 1 ▶ croak "Network ID required" unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 1 1
87  
88 1 return $self->client->delete("/networks/$id");
89 }
90  
91  
92 sub add_subnet {
93 1 ▶ my ($self, $id, %opts) = @_;
Subroutine add_subnet: called CC=6 SCAR=19.1
Pod documented
94 1 ▶ croak "Network ID required" unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 1 1
95 1 ▶ croak "ip_range required" unless $opts{ip_range};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"ip_range"} 0 1 1
96 1 ▶ croak "network_zone required" unless $opts{network_zone};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"network_zone"} 0 1 1
97 1 ▶ croak "type required" unless $opts{type};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"type"} 0 1 1
98  
99 my $body = {
100 ip_range => $opts{ip_range},
101 network_zone => $opts{network_zone},
102 type => $opts{type},
103 1 };
104 1 ▶ $body->{vswitch_id} = $opts{vswitch_id} if $opts{vswitch_id};
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"vswitch_id"} 0 1 1
105  
106 1 return $self->client->post("/networks/$id/actions/add_subnet", $body);
107 }
108  
109  
110 sub delete_subnet {
111 1 ▶ my ($self, $id, $ip_range) = @_;
Subroutine delete_subnet: called CC=3 SCAR=11.4
Pod documented
112 1 ▶ croak "Network ID required" unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 1 1
113 1 ▶ croak "ip_range required" unless $ip_range;
Branch: 1 branch
BranchTrueFalseTotal
unless $ip_range 0 1 1
114  
115 1 return $self->client->post("/networks/$id/actions/delete_subnet", {
116 ip_range => $ip_range,
117 });
118 }
119  
120  
121 sub add_route {
122 1 ▶ my ($self, $id, %opts) = @_;
Subroutine add_route: called CC=4 SCAR=14.6
Pod documented
123 1 ▶ croak "Network ID required" unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 1 1
124 1 ▶ croak "destination required" unless $opts{destination};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"destination"} 0 1 1
125 1 ▶ croak "gateway required" unless $opts{gateway};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"gateway"} 0 1 1
126  
127 return $self->client->post("/networks/$id/actions/add_route", {
128 destination => $opts{destination},
129 gateway => $opts{gateway},
130 1 });
131 }
132  
133  
134 sub delete_route {
135 1 ▶ my ($self, $id, %opts) = @_;
Subroutine delete_route: called CC=4 SCAR=14.6
Pod documented
136 1 ▶ croak "Network ID required" unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 1 1
137 1 ▶ croak "destination required" unless $opts{destination};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"destination"} 0 1 1
138 1 ▶ croak "gateway required" unless $opts{gateway};
Branch: 1 branch
BranchTrueFalseTotal
unless $opts{"gateway"} 0 1 1
139  
140 return $self->client->post("/networks/$id/actions/delete_route", {
141 destination => $opts{destination},
142 gateway => $opts{gateway},
143 1 });
144 }
145  
146  
147 25 1;
148  
149 __END__
« lib/WWW/Hetzner/Robot/CLI/Cmd/Server/Cmd/Describe.pm ↑ Summary lib/WWW/Hetzner/CLI/Cmd/Volume.pm »