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

filter: Statementstmt 100% 60 / 60 Branchbran 73.3% 22 / 30 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 14 / 14 Podpod 100% 7 / 7 totaltotal 91.2% 104 / 114 CC 17 SCAR 13.3
CC
17
Cov
90%
create
8.0
attach
4.1
resize
3.1
CRAP 3.8
« lib/WWW/Hetzner/Cloud/PrimaryIP.pm ↑ Summary lib/WWW/Hetzner/CLI/Cmd/StorageBox/Cmd/EnableSnapshotPlan.pm »
1 package WWW::Hetzner::Cloud::API::Volumes;
2 # ABSTRACT: Hetzner Cloud Volumes 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 with 'WWW::Hetzner::Role::JSONBool';
9 60 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 60 ▶use WWW::Hetzner::Cloud::Volume;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 60 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 60 has client => (
15 is => 'ro',
16 required => 1,
17 weak_ref => 1,
18 );
19  
20 60 with 'WWW::Hetzner::Role::HasActions';
21  
22 28 ▶sub _wrap {
Subroutine _wrap: called CC=1 SCAR=0.0
23 28 my ($self, $data, %extra) = @_;
24 28 return WWW::Hetzner::Cloud::Volume->new(
25 client => $self->client,
26 %$data,
27 %extra,
28 );
29 }
30  
31 15 ▶sub _wrap_list {
Subroutine _wrap_list: called CC=1 SCAR=0.0
32 15 my ($self, $list) = @_;
33 15 return [ map { $self->_wrap($_) } @$list ];
34 }
35  
36  
37 15 ▶sub _list_page {
Subroutine _list_page: called CC=2 SCAR=7.1
38 15 my ($self, %params) = @_;
39  
40 15 my $result = $self->client->get('/volumes', params => \%params);
41 15 ▶ return ($self->_wrap_list($result->{volumes} // []), $result->{meta});
Condition50%1/2
$result->{"volumes"} // []
l!l
150
MC/DC0%0/1
$result->{"volumes"} // []
$result->{"volumes"}
Truth table50%1/2
A
A= $result->{"volumes"}
Aresult
11
00
42 }
43  
44 1 ▶sub list {
Subroutine list: called CC=1 SCAR=0.0
Pod documented
45 1 my ($self, %params) = @_;
46  
47 1 my ($entities) = $self->_list_page(%params);
48 1 return $entities;
49 }
50  
51  
52  
53 3 ▶sub get {
Subroutine get: called CC=2 SCAR=7.0
Pod documented
54 3 my ($self, $id) = @_;
55 3 ▶ croak "Volume ID required" unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 3 3
56  
57 3 my $result = $self->client->get("/volumes/$id");
58 3 return $self->_wrap($result->{volume});
59 }
60  
61  
62 12 ▶sub create {
Subroutine create: called CC=8 SCAR=20.8
Pod documented
63 12 my ($self, %params) = @_;
64  
65 12 ▶ croak "name required" unless $params{name};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"name"} 1 11 12
66 11 ▶ croak "size required" unless $params{size};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"size"} 1 10 11
67 10 ▶ croak "location required" unless $params{location};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"location"} 1 9 10
68  
69 my $body = {
70 name => $params{name},
71 size => $params{size},
72 location => $params{location},
73 9 };
74  
75 9 ▶ $body->{format} = $params{format} if $params{format};
Branch: 1 branch
BranchTrueFalseTotal
if $params{"format"} 1 8 9
76 9 ▶ $body->{labels} = $params{labels} if $params{labels};
Branch: 1 branch
BranchTrueFalseTotal
if $params{"labels"} 0 9 9
77 9 ▶ $body->{automount} = _json_bool($params{automount}) if exists $params{automount};
Branch: 1 branch
BranchTrueFalseTotal
if exists $params{"automount"} 7 2 9
78 9 ▶ $body->{server} = $params{server} if $params{server};
Branch: 1 branch
BranchTrueFalseTotal
if $params{"server"} 1 8 9
79  
80 9 my $result = $self->client->post('/volumes', $body);
81 return $self->_wrap(
82 $result->{volume},
83 action => $self->_wrap_action($result->{action}),
84 9 next_actions => $self->_wrap_actions($result->{next_actions}),
85 );
86 }
87  
88  
89 2 ▶sub delete {
Subroutine delete: called CC=2 SCAR=7.1
Pod documented
90 2 my ($self, $id) = @_;
91 2 ▶ croak "Volume ID required" unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 2 2
92  
93 2 return $self->client->delete("/volumes/$id");
94 }
95  
96  
97 8 ▶sub attach {
Subroutine attach: called CC=4 SCAR=14.0
Pod documented
98 8 my ($self, $id, $server_id, %opts) = @_;
99 8 ▶ croak "Volume ID required" unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 8 8
100 8 ▶ croak "Server ID required" unless $server_id;
Branch: 1 branch
BranchTrueFalseTotal
unless $server_id 0 8 8
101  
102 8 my $body = { server => $server_id };
103 8 ▶ $body->{automount} = _json_bool($opts{automount}) if exists $opts{automount};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{"automount"} 5 3 8
104  
105 return $self->_wrap_action(
106 $self->client->post("/volumes/$id/actions/attach", $body)->{action}
107 8 );
108 }
109  
110  
111 3 ▶sub detach {
Subroutine detach: called CC=2 SCAR=7.1
Pod documented
112 3 my ($self, $id) = @_;
113 3 ▶ croak "Volume ID required" unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 3 3
114  
115 return $self->_wrap_action(
116 $self->client->post("/volumes/$id/actions/detach", {})->{action}
117 3 );
118 }
119  
120  
121 3 ▶sub resize {
Subroutine resize: called CC=3 SCAR=11.4
Pod documented
122 3 my ($self, $id, $size) = @_;
123 3 ▶ croak "Volume ID required" unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 3 3
124 3 ▶ croak "Size required" unless $size;
Branch: 1 branch
BranchTrueFalseTotal
unless $size 0 3 3
125  
126 return $self->_wrap_action(
127 $self->client->post("/volumes/$id/actions/resize", { size => $size })->{action}
128 3 );
129 }
130  
131  
132 60 1;
133  
134 __END__
« lib/WWW/Hetzner/Cloud/PrimaryIP.pm ↑ Summary lib/WWW/Hetzner/CLI/Cmd/StorageBox/Cmd/EnableSnapshotPlan.pm »