Docker/API/Configs.pm

filter: Statementstmt 100% 54 / 54 Branchbran 80.0% 16 / 20 Conditioncond 47.0% 8 / 17 MC/DCmcdc 18.1% 2 / 11 Subroutinesub 100% 14 / 14 Podpod 100% 5 / 5 totaltotal 81.8% 99 / 121 CC 17 SCAR 12.4
CC
17
Cov
86%
update
6.2
create
5.1
inspect
3.3
CRAP 3.5
« Docker/Role/RegistryAuth.pm ↑ Summary Docker/API/Plugins.pm »
1 package API::Docker::API::Configs;
2 # ABSTRACT: Docker Engine Configs 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::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 52 ▶use API::Docker::Type::Config;
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 MIME::Base64 qw( encode_base64 );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 52 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 52 has client => (
14 is => 'ro',
15 required => 1,
16 weak_ref => 1,
17 );
18  
19  
20 # The class is the caller's argument, as it is on the resource classes whose
21 # list and inspect really are two definitions -- here both are the swagger's
22 # one `Config`, and passing it keeps the seam in the same 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 6 ▶sub _wrap_list {
Subroutine _wrap_list: called CC=1 SCAR=0.0
37 6 my ($self, $class, $list) = @_;
38 6 return [ map { $self->_wrap($class, $_) } @$list ];
39 }
40  
41 # The wire field is base64; the public contract is raw bytes. Guarding the
42 # character range here keeps the failure a croak naming this class instead of
43 # MIME::Base64's "Wide character in subroutine entry" from two frames down.
44 3 ▶sub _encode_data {
Subroutine _encode_data: called CC=2 SCAR=7.1
45 3 my ($self, $method, $data) = @_;
46 3 ▶ croak __PACKAGE__ . "->$method Data must be a byte string, not decoded "
Branch: 1 branch
BranchTrueFalseTotal
if $data =~ /[^\x00-\xff]/ 0 3 3
47 . 'characters -- encode it first (Encode::encode_utf8)'
48 if $data =~ /[^\x00-\xff]/;
49 3 return encode_base64($data, '');
50 }
51  
52 7 ▶sub list {
Subroutine list: called CC=3 SCAR=11.0
Pod documented
53 7 my ($self, %opts) = @_;
54 7 my %params;
55 $params{filters} = $self->_normalise_filters($opts{filters})
56 7 ▶ if defined $opts{filters};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"filters"} 1 6 7
57 return $self->_wrap_list('API::Docker::Type::Config',
58 $self->client->get('/configs',
59 params => \%params,
60 6 ▶ %{ $self->_request_options },
Condition50%1/2
$self->client->get("/configs", "params", \%params, %{$self->_request_options;}) // []
l!l
60
MC/DC0%0/1
$self->client->get("/configs", "params", \%params, %{$self->_request_options;}) // []
$self->client->get("/configs", "params", \%params, %{$self->_request_options;})
Truth table50%1/2
A
A= $self->client->get("/configs", "params", \%params, %{$self->_request_options;})
Aresult
11
00
61 ) // []);
62 }
63  
64  
65 3 ▶sub create {
Subroutine create: called CC=5 SCAR=16.2
Pod documented
66 3 my ($self, %spec) = @_;
67 croak __PACKAGE__ . '->create Name required'
68 3 ▶ unless defined $spec{Name} && length $spec{Name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spec{"Name"} and length $spec{"Name"} 1 2 3
Condition66%2/3
defined $spec{"Name"} and length $spec{"Name"}
!ll&&!rl&&r
102
MC/DC50%1/2
defined $spec{"Name"} and length $spec{"Name"}
defined $spec{"Name"} length $spec{"Name"}
Truth table66%2/3
A and B
A= defined $spec{"Name"}B= length $spec{"Name"}
ABresult
0X0
100
111
69 croak __PACKAGE__ . '->create Data required'
70 2 ▶ unless defined $spec{Data} && length $spec{Data};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spec{"Data"} and length $spec{"Data"} 1 1 2
Condition66%2/3
defined $spec{"Data"} and length $spec{"Data"}
!ll&&!rl&&r
101
MC/DC50%1/2
defined $spec{"Data"} and length $spec{"Data"}
defined $spec{"Data"} length $spec{"Data"}
Truth table66%2/3
A and B
A= defined $spec{"Data"}B= length $spec{"Data"}
ABresult
0X0
100
111
71 1 $spec{Data} = $self->_encode_data('create', $spec{Data});
72 1 return $self->client->post('/configs/create', \%spec);
73 }
74  
75  
76 5 ▶sub inspect {
Subroutine inspect: called CC=3 SCAR=12.0
Pod documented
77 5 my ($self, $id) = @_;
78 5 ▶ croak __PACKAGE__ . '->inspect config ID or name required'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id and length $id 0 5 5
Condition33%1/3
defined $id and length $id
!ll&&!rl&&r
005
MC/DC0%0/2
defined $id and length $id
defined $id length $id
Truth table33%1/3
A and B
A= defined $idB= length $id
ABresult
0X0
100
111
79 unless defined $id && length $id;
80 return $self->_wrap('API::Docker::Type::Config',
81 $self->client->get("/configs/$id",
82 5 %{ $self->_request_options },
83 ));
84 }
85  
86  
87 5 ▶sub update {
Subroutine update: called CC=6 SCAR=18.2
Pod documented
88 5 my ($self, $id, $version, %spec) = @_;
89 5 ▶ croak __PACKAGE__ . '->update config ID or name required'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id and length $id 0 5 5
Condition33%1/3
defined $id and length $id
!ll&&!rl&&r
005
MC/DC0%0/2
defined $id and length $id
defined $id length $id
Truth table33%1/3
A and B
A= defined $idB= length $id
ABresult
0X0
100
111
90 unless defined $id && length $id;
91 5 ▶ croak __PACKAGE__ . '->update requires the current version as its second '
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version 1 4 5
92 . 'argument: the Version.Index from inspect($id), which the daemon uses '
93 . 'as an optimistic-concurrency token and will not accept the update '
94 . 'without'
95 unless defined $version;
96 4 ▶ croak __PACKAGE__ . '->update version must be the numeric Version.Index '
Branch: 1 branch
BranchTrueFalseTotal
unless $version =~ /\A[0-9]+\z/ 1 3 4
97 . "from inspect(\$id), got '$version'"
98 unless $version =~ /\A[0-9]+\z/;
99 $spec{Data} = $self->_encode_data('update', $spec{Data})
100 3 ▶ if defined $spec{Data};
Branch: 1 branch
BranchTrueFalseTotal
if defined $spec{"Data"} 2 1 3
101 3 return $self->client->post("/configs/$id/update", \%spec,
102 params => { version => $version });
103 }
104  
105  
106 5 ▶sub remove {
Subroutine remove: called CC=3 SCAR=12.0
Pod documented
107 5 my ($self, $id) = @_;
108 5 ▶ croak __PACKAGE__ . '->remove config ID or name required'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id and length $id 0 5 5
Condition33%1/3
defined $id and length $id
!ll&&!rl&&r
005
MC/DC0%0/2
defined $id and length $id
defined $id length $id
Truth table33%1/3
A and B
A= defined $idB= length $id
ABresult
0X0
100
111
109 unless defined $id && length $id;
110 return $self->client->delete_request("/configs/$id",
111 5 %{ $self->_request_options },
112 );
113 }
114  
115  
116  
117 52 1;
118  
119 __END__
« Docker/Role/RegistryAuth.pm ↑ Summary Docker/API/Plugins.pm »