lib/WWW/Hetzner/Cloud/Volume.pm

filter: Statementstmt 43.5% 27 / 62 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 40.0% 6 / 15 Podpod 100% 9 / 9 totaltotal 38.5% 42 / 109 CC 12 SCAR 23.3
CC
12
Cov
32%
attach
30.0
resize
12.0
refresh
12.0
CRAP 10.3
« lib/WWW/Hetzner/CLI/Cmd/Zone/Cmd/List.pm ↑ Summary lib/WWW/Hetzner/Cloud/LoadBalancer.pm »
1 package WWW::Hetzner::Cloud::Volume;
2 # ABSTRACT: Hetzner Cloud Volume object
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 namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 25 has _client => (
12 is => 'ro',
13 required => 1,
14 weak_ref => 1,
15 init_arg => 'client',
16 );
17  
18 25 has id => ( is => 'ro' );
19  
20  
21 25 has name => ( is => 'rw' );
22  
23  
24 25 has status => ( is => 'rwp' );
25  
26  
27 25 has size => ( is => 'ro' );
28  
29  
30 25 has server => ( is => 'ro' );
31  
32  
33 25 has created => ( is => 'ro' );
34  
35  
36 0 ▶has labels => ( is => 'rw', default => sub { {} } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
37  
38  
39 25 has linux_device => ( is => 'ro' );
40  
41  
42 25 has format => ( is => 'ro' );
43  
44  
45 0 ▶has protection => ( is => 'ro', default => sub { {} } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
46  
47  
48 # Nested data
49 0 ▶has location_data => ( is => 'ro', init_arg => 'location', default => sub { {} } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
50  
51 # Convenience accessors
52 1 ▶sub location { shift->location_data->{name} }
Subroutine location: called CC=1 SCAR=0.0
Pod documented
53  
54  
55 2 ▶sub is_attached { defined shift->server }
Subroutine is_attached: called CC=1 SCAR=0.0
Pod documented
56  
57  
58 # Actions
59 sub update {
60 0 ▶ my ($self) = @_;
Subroutine update: not called CC=2 SCAR=17.9
Pod documented
61 0 ▶ croak "Cannot update volume without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
62  
63 0 my $result = $self->_client->put("/volumes/" . $self->id, {
64 name => $self->name,
65 labels => $self->labels,
66 });
67 0 return $self;
68 }
69  
70  
71 sub delete {
72 0 ▶ my ($self) = @_;
Subroutine delete: not called CC=2 SCAR=17.9
Pod documented
73 0 ▶ croak "Cannot delete volume without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
74  
75 0 $self->_client->delete("/volumes/" . $self->id);
76 0 return 1;
77 }
78  
79  
80 sub attach {
81 0 ▶ my ($self, $server_id, %opts) = @_;
Subroutine attach: not called CC=5 SCAR=34.0
Pod documented
82 0 ▶ croak "Cannot attach volume without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
83 0 ▶ croak "Server ID required" unless $server_id;
Branch: 1 branch
BranchTrueFalseTotal
unless $server_id 0 0 0
84  
85 0 my $body = { server => $server_id };
86 0 ▶ $body->{automount} = $opts{automount} ? \1 : \0 if exists $opts{automount};
Branch: 2 branches
BranchTrueFalseTotal
if exists $opts{"automount"} 0 0 0
$opts{'automount'} ? : 0 0 0
87  
88 0 $self->_client->post("/volumes/" . $self->id . "/actions/attach", $body);
89 0 return $self;
90 }
91  
92  
93 sub detach {
94 0 ▶ my ($self) = @_;
Subroutine detach: not called CC=2 SCAR=17.9
Pod documented
95 0 ▶ croak "Cannot detach volume without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
96  
97 0 $self->_client->post("/volumes/" . $self->id . "/actions/detach", {});
98 0 return $self;
99 }
100  
101  
102 sub resize {
103 0 ▶ my ($self, $size) = @_;
Subroutine resize: not called CC=3 SCAR=24.8
Pod documented
104 0 ▶ croak "Cannot resize volume without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
105 0 ▶ croak "Size required" unless $size;
Branch: 1 branch
BranchTrueFalseTotal
unless $size 0 0 0
106  
107 0 $self->_client->post("/volumes/" . $self->id . "/actions/resize", { size => $size });
108 0 return $self;
109 }
110  
111  
112 sub refresh {
113 0 ▶ my ($self) = @_;
Subroutine refresh: not called CC=3 SCAR=24.8
Pod documented
114 0 ▶ croak "Cannot refresh volume without ID" unless $self->id;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->id 0 0 0
115  
116 0 my $result = $self->_client->get("/volumes/" . $self->id);
117 0 my $data = $result->{volume};
118  
119 0 $self->_set_status($data->{status});
120 0 $self->name($data->{name});
121 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
122  
123 0 return $self;
124 }
125  
126  
127 sub data {
128 1 ▶ my ($self) = @_;
Subroutine data: called CC=1 SCAR=0.0
Pod documented
129 return {
130 1 id => $self->id,
131 name => $self->name,
132 status => $self->status,
133 size => $self->size,
134 server => $self->server,
135 created => $self->created,
136 labels => $self->labels,
137 linux_device => $self->linux_device,
138 format => $self->format,
139 protection => $self->protection,
140 location => $self->location_data,
141 };
142 }
143  
144  
145  
146 25 1.
147  
148 __END__
« lib/WWW/Hetzner/CLI/Cmd/Zone/Cmd/List.pm ↑ Summary lib/WWW/Hetzner/Cloud/LoadBalancer.pm »