Docker/API/Volumes.pm

filter: Statementstmt 100% 49 / 49 Branchbran 91.6% 11 / 12 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 12 / 12 Podpod 100% 5 / 5 totaltotal 96.3% 78 / 81 CC 8 SCAR 7.7
CC
8
Cov
97%
remove
4.0
list
3.0
inspect
2.0
CRAP 2.2
« Docker/Role/Using.pm ↑ Summary Docker/API/Networks.pm »
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
BranchTrueFalseTotal
if defined $opts{"filters"} 1 5 6
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"} // []
l!l
50
MC/DC0%0/1
$result->{"Volumes"} // []
$result->{"Volumes"}
Truth table50%1/2
A
A= $result->{"Volumes"}
Aresult
11
00
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
BranchTrueFalseTotal
unless $name 1 6 7
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
BranchTrueFalseTotal
unless $name 1 5 6
75 5 my %params;
76 5 ▶ $params{force} = $opts{force} ? 1 : 0 if defined $opts{force};
Branch: 2 branches
BranchTrueFalseTotal
if defined $opts{"force"} 1 4 5
$opts{'force'} ? : 1 0 1
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
BranchTrueFalseTotal
if defined $opts{"filters"} 2 3 5
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__
« Docker/Role/Using.pm ↑ Summary Docker/API/Networks.pm »