| 1 | package API::Docker::API::Volumes; | ||||||||||||||
| 2 | # ABSTRACT: Docker Engine Volumes API | ||||||||||||||
| 3 | 52 | our $VERSION = '0.006'; | |||||||||||||
| 4 | 52 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 52 | with 'API::Docker::Role::Filters', 'API::Docker::Role::Using'; | |||||||||||||
| 6 | 52 | ▶ | use API::Docker::Role::Entity::Volume; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 52 | ▶ | use API::Docker::Type::Volume; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 52 | ▶ | use Carp qw( croak ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 52 | ▶ | use namespace::clean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | |||||||||||||||
| 11 | |||||||||||||||
| 12 | 52 | has client => ( | |||||||||||||
| 13 | is => 'ro', | ||||||||||||||
| 14 | required => 1, | ||||||||||||||
| 15 | weak_ref => 1, | ||||||||||||||
| 16 | ); | ||||||||||||||
| 17 | |||||||||||||||
| 18 | |||||||||||||||
| 19 | # The class is the caller's argument, as it is on the resource classes whose | ||||||||||||||
| 20 | # list and inspect really are two definitions -- here all three calls answer | ||||||||||||||
| 21 | # with the swagger's one `Volume`, and passing it keeps the seam in the same | ||||||||||||||
| 22 | # place. | ||||||||||||||
| 23 | # | ||||||||||||||
| 24 | # from_data, not new: this is a daemon response, and the two entry points of | ||||||||||||||
| 25 | # API::Docker::Role::Type read it differently. from_data takes the swagger's | ||||||||||||||
| 26 | # wire names and nothing else, so a key it has not heard of keeps its own | ||||||||||||||
| 27 | # spelling instead of being read as the Perl name of one it has, and a value | ||||||||||||||
| 28 | # that disagrees with the swagger costs its own field rather than the whole | ||||||||||||||
| 29 | # response. `client` is ours rather than the engine's, so it goes beside the | ||||||||||||||
| 30 | # data instead of into it. | ||||||||||||||
| 31 | 8 | ▶ | sub _wrap { | ||||||||||||
|
Subroutine
_wrap: called CC=1 SCAR=0.0
| |||||||||||||||
| 32 | 8 | my ($self, $class, $data) = @_; | |||||||||||||
| 33 | 8 | return $class->from_data($data, client => $self->client); | |||||||||||||
| 34 | } | ||||||||||||||
| 35 | |||||||||||||||
| 36 | 5 | ▶ | sub _wrap_list { | ||||||||||||
|
Subroutine
_wrap_list: called CC=1 SCAR=0.0
| |||||||||||||||
| 37 | 5 | my ($self, $class, $list) = @_; | |||||||||||||
| 38 | 5 | return [ map { $self->_wrap($class, $_) } @$list ]; | |||||||||||||
| 39 | } | ||||||||||||||
| 40 | |||||||||||||||
| 41 | 6 | ▶ | sub list { | ||||||||||||
|
Subroutine
list: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||
| 42 | 6 | my ($self, %opts) = @_; | |||||||||||||
| 43 | 6 | my %params; | |||||||||||||
| 44 | $params{filters} = $self->_normalise_filters($opts{filters}) | ||||||||||||||
| 45 | 6 | ▶ | if defined $opts{filters}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 46 | my $result = $self->client->get('/volumes', | ||||||||||||||
| 47 | params => \%params, | ||||||||||||||
| 48 | 5 | %{ $self->_request_options }, | |||||||||||||
| 49 | ); | ||||||||||||||
| 50 | return $self->_wrap_list('API::Docker::Type::Volume', | ||||||||||||||
| 51 | 5 | ▶ | $result->{Volumes} // []); | ||||||||||||
|
Condition50%1/2
$result->{"Volumes"} // []
MC/DC0%0/1
$result->{"Volumes"} // []
$result->{"Volumes"}
Truth table50%1/2
A
A= $result->{"Volumes"}
| |||||||||||||||
| 52 | } | ||||||||||||||
| 53 | |||||||||||||||
| 54 | |||||||||||||||
| 55 | 1 | ▶ | sub create { | ||||||||||||
|
Subroutine
create: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 56 | 1 | my ($self, %config) = @_; | |||||||||||||
| 57 | 1 | my $result = $self->client->post('/volumes/create', \%config); | |||||||||||||
| 58 | 1 | return $self->_wrap('API::Docker::Type::Volume', $result); | |||||||||||||
| 59 | } | ||||||||||||||
| 60 | |||||||||||||||
| 61 | |||||||||||||||
| 62 | 7 | ▶ | sub inspect { | ||||||||||||
|
Subroutine
inspect: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||
| 63 | 7 | my ($self, $name) = @_; | |||||||||||||
| 64 | 7 | ▶ | croak "Volume name required" unless $name; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 65 | my $result = $self->client->get("/volumes/$name", | ||||||||||||||
| 66 | 6 | %{ $self->_request_options }, | |||||||||||||
| 67 | ); | ||||||||||||||
| 68 | 5 | return $self->_wrap('API::Docker::Type::Volume', $result); | |||||||||||||
| 69 | } | ||||||||||||||
| 70 | |||||||||||||||
| 71 | |||||||||||||||
| 72 | 6 | ▶ | sub remove { | ||||||||||||
|
Subroutine
remove: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||
| 73 | 6 | my ($self, $name, %opts) = @_; | |||||||||||||
| 74 | 6 | ▶ | croak "Volume name required" unless $name; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 75 | 5 | my %params; | |||||||||||||
| 76 | 5 | ▶ | $params{force} = $opts{force} ? 1 : 0 if defined $opts{force}; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 77 | return $self->client->delete_request("/volumes/$name", | ||||||||||||||
| 78 | params => \%params, | ||||||||||||||
| 79 | 5 | %{ $self->_request_options }, | |||||||||||||
| 80 | ); | ||||||||||||||
| 81 | } | ||||||||||||||
| 82 | |||||||||||||||
| 83 | |||||||||||||||
| 84 | 5 | ▶ | sub prune { | ||||||||||||
|
Subroutine
prune: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||
| 85 | 5 | my ($self, %opts) = @_; | |||||||||||||
| 86 | 5 | my %params; | |||||||||||||
| 87 | $params{filters} = $self->_normalise_filters($opts{filters}) | ||||||||||||||
| 88 | 5 | ▶ | if defined $opts{filters}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 89 | return $self->client->post('/volumes/prune', undef, | ||||||||||||||
| 90 | params => \%params, | ||||||||||||||
| 91 | 4 | %{ $self->_request_options }, | |||||||||||||
| 92 | ); | ||||||||||||||
| 93 | } | ||||||||||||||
| 94 | |||||||||||||||
| 95 | |||||||||||||||
| 96 | |||||||||||||||
| 97 | 52 | 1; | |||||||||||||
| 98 | |||||||||||||||
| 99 | __END__ | ||||||||||||||