| 1 | package WWW::Hetzner::Action; | ||||||||||||||||||||
| 2 | # ABSTRACT: Hetzner API action object | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 60 | our $VERSION = '0.102'; | |||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 60 | ▶ | use Moo; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 60 | ▶ | use Carp qw(croak); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 60 | ▶ | use namespace::clean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 60 | has _client => ( | |||||||||||||||||||
| 12 | is => 'ro', | ||||||||||||||||||||
| 13 | required => 1, | ||||||||||||||||||||
| 14 | weak_ref => 1, | ||||||||||||||||||||
| 15 | init_arg => 'client', | ||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 9 | ▶ | has poll_path => ( is => 'ro', default => sub { '/actions' } ); | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 60 | has id => ( is => 'ro' ); | |||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 60 | has command => ( is => 'ro' ); | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 60 | has status => ( is => 'rwp' ); | |||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 60 | has progress => ( is => 'rwp' ); | |||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 60 | has started => ( is => 'ro' ); | |||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 60 | has finished => ( is => 'ro' ); | |||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 34 | ▶ | has resources => ( is => 'ro', default => sub { [] } ); | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 60 | has error => ( is => 'rwp' ); | |||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 200 | ▶ | has result => ( is => 'ro', default => sub { {} } ); | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 9 | ▶ | sub root_password { shift->result->{root_password} } | ||||||||||||||||||
|
Subroutine
root_password: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 0 | ▶ | sub image { shift->result->{image} } | ||||||||||||||||||
|
Subroutine
image: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 1 | ▶ | sub wss_url { shift->result->{wss_url} } | ||||||||||||||||||
|
Subroutine
wss_url: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 1 | ▶ | sub password { shift->result->{password} } | ||||||||||||||||||
|
Subroutine
password: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 47 | ▶ | sub is_running { shift->status eq 'running' } | ||||||||||||||||||
|
Subroutine
is_running: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 2 | ▶ | sub is_success { shift->status eq 'success' } | ||||||||||||||||||
|
Subroutine
is_success: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 25 | ▶ | sub is_error { shift->status eq 'error' } | ||||||||||||||||||
|
Subroutine
is_error: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 4 | ▶ | sub error_message { | ||||||||||||||||||
|
Subroutine
error_message: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||
| 70 | 4 | my ($self) = @_; | |||||||||||||||||||
| 71 | 4 | my $error = $self->error; | |||||||||||||||||||
| 72 | 4 | ▶ | return ref $error ? $error->{message} : undef; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 23 | ▶ | sub refresh { | ||||||||||||||||||
|
Subroutine
refresh: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 77 | 23 | my ($self) = @_; | |||||||||||||||||||
| 78 | 23 | ▶ | croak "Cannot refresh action without ID" unless $self->id; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 23 | my $result = $self->_client->get($self->poll_path . '/' . $self->id); | |||||||||||||||||||
| 81 | 23 | my $data = $result->{action}; | |||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 23 | $self->_set_status($data->{status}); | |||||||||||||||||||
| 84 | 23 | $self->_set_progress($data->{progress}); | |||||||||||||||||||
| 85 | 23 | $self->_set_error($data->{error}); | |||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 23 | return $self; | |||||||||||||||||||
| 88 | } | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 23 | ▶ | sub wait { | ||||||||||||||||||
|
Subroutine
wait: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||
| 92 | 23 | my ($self, %opts) = @_; | |||||||||||||||||||
| 93 | 23 | ▶ | my $interval = $opts{interval} // 1; | ||||||||||||||||||
|
Condition100%2/2
$opts{"interval"} // 1
MC/DC100%1/1
$opts{"interval"} // 1
$opts{"interval"}
Truth table100%2/2
A
A= $opts{"interval"}
| |||||||||||||||||||||
| 94 | 23 | ▶ | my $timeout = $opts{timeout} // 120; | ||||||||||||||||||
|
Condition100%2/2
$opts{"timeout"} // 120
MC/DC100%1/1
$opts{"timeout"} // 120
$opts{"timeout"}
Truth table100%2/2
A
A= $opts{"timeout"}
| |||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | 23 | my $waited = 0; | |||||||||||||||||||
| 97 | 23 | ▶ | while ($self->is_running) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 98 | 24 | ▶ | croak sprintf('Timed out waiting for action %s (%s)', $self->id, $self->command) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 99 | if $waited >= $timeout; | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 22 | $self->_client->sleeper->($interval); | |||||||||||||||||||
| 102 | 22 | $waited += $interval; | |||||||||||||||||||
| 103 | 22 | $self->refresh; | |||||||||||||||||||
| 104 | } | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 21 | ▶ | croak sprintf('Action %s (%s) failed: %s', | ||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->error_message // "unknown"
MC/DC0%0/1
$self->error_message // "unknown"
$self->error_message
Truth table50%1/2
A
A= $self->error_message
| |||||||||||||||||||||
| 107 | $self->id, $self->command, $self->error_message // 'unknown') | ||||||||||||||||||||
| 108 | if $self->is_error; | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 18 | return $self; | |||||||||||||||||||
| 111 | } | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | 3 | ▶ | sub data { | ||||||||||||||||||
|
Subroutine
data: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 115 | 3 | my ($self) = @_; | |||||||||||||||||||
| 116 | return { | ||||||||||||||||||||
| 117 | 3 | id => $self->id, | |||||||||||||||||||
| 118 | command => $self->command, | ||||||||||||||||||||
| 119 | status => $self->status, | ||||||||||||||||||||
| 120 | progress => $self->progress, | ||||||||||||||||||||
| 121 | started => $self->started, | ||||||||||||||||||||
| 122 | finished => $self->finished, | ||||||||||||||||||||
| 123 | resources => $self->resources, | ||||||||||||||||||||
| 124 | error => $self->error, | ||||||||||||||||||||
| 125 | }; | ||||||||||||||||||||
| 126 | } | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | 60 | 1. | |||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | __END__ | ||||||||||||||||||||