| 1 | package WWW::Hetzner::Storage::API::Snapshots; | ||||||||||||
| 2 | # ABSTRACT: Hetzner Storage Box Snapshots API | ||||||||||||
| 3 | |||||||||||||
| 4 | 11 | our $VERSION = '0.102'; | |||||||||||
| 5 | |||||||||||||
| 6 | 11 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 11 | ▶ | use Carp qw(croak); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 11 | ▶ | use WWW::Hetzner::Storage::Snapshot; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 11 | ▶ | use namespace::clean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | |||||||||||||
| 12 | 11 | has client => ( | |||||||||||
| 13 | is => 'ro', | ||||||||||||
| 14 | required => 1, | ||||||||||||
| 15 | weak_ref => 1, | ||||||||||||
| 16 | ); | ||||||||||||
| 17 | |||||||||||||
| 18 | 11 | has storage_box_id => ( | |||||||||||
| 19 | is => 'ro', | ||||||||||||
| 20 | required => 1, | ||||||||||||
| 21 | ); | ||||||||||||
| 22 | |||||||||||||
| 23 | 11 | with 'WWW::Hetzner::Role::HasActions'; | |||||||||||
| 24 | |||||||||||||
| 25 | has '+action_poll_path' => ( | ||||||||||||
| 26 | 15 | ▶ | default => sub { '/storage_boxes/actions' }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 27 | 11 | ); | |||||||||||
| 28 | |||||||||||||
| 29 | 21 | ▶ | sub _base_path { | ||||||||||
|
Subroutine
_base_path: called CC=1 SCAR=0.0
| |||||||||||||
| 30 | 21 | my ($self) = @_; | |||||||||||
| 31 | 21 | return '/storage_boxes/' . $self->storage_box_id . '/snapshots'; | |||||||||||
| 32 | } | ||||||||||||
| 33 | |||||||||||||
| 34 | 21 | ▶ | sub _wrap { | ||||||||||
|
Subroutine
_wrap: called CC=1 SCAR=0.0
| |||||||||||||
| 35 | 21 | my ($self, $data, %extra) = @_; | |||||||||||
| 36 | 21 | return WWW::Hetzner::Storage::Snapshot->new( | |||||||||||
| 37 | client => $self->client, | ||||||||||||
| 38 | storage_box_id => $self->storage_box_id, | ||||||||||||
| 39 | %$data, | ||||||||||||
| 40 | %extra, | ||||||||||||
| 41 | ); | ||||||||||||
| 42 | } | ||||||||||||
| 43 | |||||||||||||
| 44 | 4 | ▶ | sub _wrap_list { | ||||||||||
|
Subroutine
_wrap_list: called CC=2 SCAR=7.0
| |||||||||||||
| 45 | 4 | my ($self, $list) = @_; | |||||||||||
| 46 | 4 | ▶ | return [ map { $self->_wrap($_) } @{ $list // [] } ]; | ||||||||||
|
Condition50%1/2
$list // []
MC/DC0%0/1
$list // []
$list
Truth table50%1/2
A
A= $list
| |||||||||||||
| 47 | } | ||||||||||||
| 48 | |||||||||||||
| 49 | |||||||||||||
| 50 | 4 | ▶ | sub list { | ||||||||||
|
Subroutine
list: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||
| 51 | 4 | my ($self, %params) = @_; | |||||||||||
| 52 | |||||||||||||
| 53 | 4 | my $result = $self->client->get($self->_base_path, params => \%params); | |||||||||||
| 54 | 4 | ▶ | return $self->_wrap_list($result->{snapshots} // []); | ||||||||||
|
Condition50%1/2
$result->{"snapshots"} // []
MC/DC0%0/1
$result->{"snapshots"} // []
$result->{"snapshots"}
Truth table50%1/2
A
A= $result->{"snapshots"}
| |||||||||||||
| 55 | } | ||||||||||||
| 56 | |||||||||||||
| 57 | |||||||||||||
| 58 | 5 | ▶ | sub get { | ||||||||||
|
Subroutine
get: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||
| 59 | 5 | my ($self, $id) = @_; | |||||||||||
| 60 | 5 | ▶ | croak 'Snapshot ID required' unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 61 | |||||||||||||
| 62 | 5 | my $result = $self->client->get($self->_base_path . "/$id"); | |||||||||||
| 63 | 5 | return $self->_wrap($result->{snapshot}); | |||||||||||
| 64 | } | ||||||||||||
| 65 | |||||||||||||
| 66 | |||||||||||||
| 67 | 3 | ▶ | sub create { | ||||||||||
|
Subroutine
create: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 68 | 3 | my ($self, %params) = @_; | |||||||||||
| 69 | |||||||||||||
| 70 | 3 | my $body = {}; | |||||||||||
| 71 | 3 | for my $field (qw(description labels)) { | |||||||||||
| 72 | 6 | ▶ | $body->{$field} = $params{$field} if exists $params{$field}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 73 | } | ||||||||||||
| 74 | |||||||||||||
| 75 | 3 | my $result = $self->client->post($self->_base_path, $body); | |||||||||||
| 76 | return $self->_wrap( | ||||||||||||
| 77 | $result->{snapshot}, | ||||||||||||
| 78 | 3 | action => $self->_wrap_action($result->{action}), | |||||||||||
| 79 | ); | ||||||||||||
| 80 | } | ||||||||||||
| 81 | |||||||||||||
| 82 | |||||||||||||
| 83 | 5 | ▶ | sub update { | ||||||||||
|
Subroutine
update: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 84 | 5 | my ($self, $id, %params) = @_; | |||||||||||
| 85 | 5 | ▶ | croak 'Snapshot ID required' unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 86 | |||||||||||||
| 87 | 5 | my $body = {}; | |||||||||||
| 88 | 5 | for my $field (qw(description labels)) { | |||||||||||
| 89 | 10 | ▶ | $body->{$field} = $params{$field} if exists $params{$field}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 90 | } | ||||||||||||
| 91 | |||||||||||||
| 92 | 5 | my $result = $self->client->put($self->_base_path . "/$id", $body); | |||||||||||
| 93 | 5 | return $self->_wrap($result->{snapshot}); | |||||||||||
| 94 | } | ||||||||||||
| 95 | |||||||||||||
| 96 | |||||||||||||
| 97 | 4 | ▶ | sub delete { | ||||||||||
|
Subroutine
delete: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||
| 98 | 4 | my ($self, $id) = @_; | |||||||||||
| 99 | 4 | ▶ | croak 'Snapshot ID required' unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 100 | |||||||||||||
| 101 | 4 | my $result = $self->client->delete($self->_base_path . "/$id"); | |||||||||||
| 102 | 4 | return $self->_wrap_action($result->{action}); | |||||||||||
| 103 | } | ||||||||||||
| 104 | |||||||||||||
| 105 | |||||||||||||
| 106 | 11 | 1; | |||||||||||
| 107 | |||||||||||||
| 108 | __END__ | ||||||||||||