lib/WWW/Hetzner/Cloud/Volume.pm

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