File Coverage

blib/lib/WebService/DigitalOcean/Role/DropletActions.pm
Criterion Covered Total %
statement 18 66 27.2
branch n/a
condition n/a
subroutine 6 23 26.0
pod 16 16 100.0
total 40 105 38.1


line stmt bran cond sub pod time code
1             package WebService::DigitalOcean::Role::DropletActions;
2             # ABSTRACT: Droplet Actions role for DigitalOcean WebService
3 2     2   1361 use utf8;
  2         5  
  2         11  
4 2     2   70 use Moo::Role;
  2         4  
  2         14  
5 2     2   619 use feature 'state';
  2         3  
  2         153  
6 2     2   10 use Types::Standard qw/Str Enum Object Dict Int Bool/;
  2         3  
  2         14  
7 2     2   1798 use Type::Utils;
  2         4  
  2         11  
8 2     2   2412 use Type::Params qw/compile multisig/;
  2         4  
  2         11  
9              
10             requires 'make_request';
11              
12             our $VERSION = '0.024'; # VERSION
13              
14             sub droplet_resize {
15 0     0 1   state $check = compile(
16             Object,
17             Dict[
18             droplet => Int,
19             disk => Bool,
20             size => Str,
21             ],
22             );
23 0           my ($self, $opts) = $check->(@_);
24              
25 0           $opts->{type} = 'resize';
26              
27 0           return $self->_droplet_action_start($opts);
28             }
29              
30             sub droplet_change_kernel {
31 0     0 1   state $check = compile(
32             Object,
33             Dict[
34             droplet => Int,
35             kernel => Int,
36             ],
37             );
38 0           my ($self, $opts) = $check->(@_);
39              
40 0           $opts->{type} = 'change_kernel';
41              
42 0           return $self->_droplet_action_start($opts);
43             }
44              
45             sub droplet_rebuild {
46 0     0 1   state $check = compile(
47             Object,
48             Dict[
49             droplet => Int,
50             image => Str,
51             ],
52             );
53 0           my ($self, $opts) = $check->(@_);
54              
55 0           $opts->{type} = 'rebuild';
56              
57 0           return $self->_droplet_action_start($opts);
58             }
59              
60             sub droplet_restore {
61 0     0 1   state $check = compile(
62             Object,
63             Dict[
64             droplet => Int,
65             image => Str,
66             ],
67             );
68 0           my ($self, $opts) = $check->(@_);
69              
70 0           $opts->{type} = 'restore';
71              
72 0           return $self->_droplet_action_start($opts);
73             }
74              
75             sub droplet_rename {
76 0     0 1   state $check = compile(
77             Object,
78             Dict[
79             droplet => Int,
80             name => Str,
81             ],
82             );
83 0           my ($self, $opts) = $check->(@_);
84              
85 0           $opts->{type} = 'rename';
86              
87 0           return $self->_droplet_action_start($opts);
88             }
89              
90             sub droplet_snapshot {
91 0     0 1   state $check = compile(
92             Object,
93             Dict[
94             droplet => Int,
95             name => Str,
96             ],
97             );
98 0           my ($self, $opts) = $check->(@_);
99              
100 0           $opts->{type} = 'snapshot';
101              
102 0           return $self->_droplet_action_start($opts);
103             }
104              
105             {
106             my $Check_Self_and_ID = compile( Object, Int );
107              
108             sub droplet_reboot {
109 0     0 1   my ($self, $id) = $Check_Self_and_ID->(@_);
110              
111 0           return $self->_droplet_action_start({
112             droplet => $id,
113             type => 'reboot',
114             });
115             }
116              
117             sub droplet_power_cycle {
118 0     0 1   my ($self, $id) = $Check_Self_and_ID->(@_);
119              
120 0           return $self->_droplet_action_start({
121             droplet => $id,
122             type => 'power_cycle',
123             });
124             }
125              
126             sub droplet_power_on {
127 0     0 1   my ($self, $id) = $Check_Self_and_ID->(@_);
128              
129 0           return $self->_droplet_action_start({
130             droplet => $id,
131             type => 'power_on',
132             });
133             }
134              
135             sub droplet_power_off {
136 0     0 1   my ($self, $id) = $Check_Self_and_ID->(@_);
137              
138 0           return $self->_droplet_action_start({
139             droplet => $id,
140             type => 'power_off',
141             });
142             }
143              
144             sub droplet_password_reset {
145 0     0 1   my ($self, $id) = $Check_Self_and_ID->(@_);
146              
147 0           return $self->_droplet_action_start({
148             droplet => $id,
149             type => 'password_reset',
150             });
151             }
152              
153             sub droplet_shutdown {
154 0     0 1   my ($self, $id) = $Check_Self_and_ID->(@_);
155              
156 0           return $self->_droplet_action_start({
157             droplet => $id,
158             type => 'shutdown',
159             });
160             }
161              
162             sub droplet_enable_ipv6 {
163 0     0 1   my ($self, $id) = $Check_Self_and_ID->(@_);
164              
165 0           return $self->_droplet_action_start({
166             droplet => $id,
167             type => 'enable_ipv6',
168             });
169             }
170              
171             sub droplet_enable_private_networking {
172 0     0 1   my ($self, $id) = $Check_Self_and_ID->(@_);
173              
174 0           return $self->_droplet_action_start({
175             droplet => $id,
176             type => 'enable_private_networking',
177             });
178             }
179              
180             sub droplet_disable_backups {
181 0     0 1   my ($self, $id) = $Check_Self_and_ID->(@_);
182              
183 0           return $self->_droplet_action_start({
184             droplet => $id,
185             type => 'disable_backups',
186             });
187             }
188             }
189              
190             sub droplet_action_get {
191 0     0 1   state $check = compile(
192             Object,
193             Dict[
194             droplet => Int,
195             action => Int,
196             ],
197             );
198              
199 0           my ($self, $opts) = $check->(@_);
200              
201 0           return $self->make_request(GET => "/droplets/$opts->{droplet}/actions/$opts->{action}");
202             }
203              
204             sub _droplet_action_start {
205 0     0     my ($self, $opts) = @_;
206              
207 0           my $droplet = delete $opts->{droplet};
208              
209 0           return $self->make_request(POST => "/droplets/$droplet/actions", $opts);
210             }
211              
212             1;
213              
214             __END__