Docker/Role/Entity/Config.pm

filter: Statementstmt 95.7% 45 / 47 Branchbran 90.0% 9 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.9% 10 / 11 Podpod 100% 5 / 5 totaltotal 94.5% 69 / 73 CC 5 SCAR 5.5
CC
5
Cov
95%
decoded_data
3.0
version_index
2.0
inspect
2.0
CRAP 1.7
« Docker/API/Networks.pm ↑ Summary Docker/Role/Entity/Container.pm »
1 package API::Docker::Role::Entity::Config;
2 # ABSTRACT: Config operations, on the generated config type
3 52 our $VERSION = '0.006';
4 52 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 52 with 'API::Docker::Role::Entity';
6 52 requires 'id';
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( decode_base64 );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 52 ▶use Package::Stash;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 52 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 6 ▶sub decoded_data {
Subroutine decoded_data: called CC=3 SCAR=11.0
Pod documented
15 6 my ($self) = @_;
16 6 my $spec = $self->spec;
17 6 ▶ return unless defined $spec;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spec 1 5 6
18 5 my $data = $spec->data;
19 5 ▶ return unless defined $data;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 1 4 5
20 4 return decode_base64($data);
21 }
22  
23  
24 6 ▶sub version_index {
Subroutine version_index: called CC=2 SCAR=6.9
Pod documented
25 6 my ($self) = @_;
26 6 my $version = $self->version;
27 6 ▶ return unless defined $version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version 2 4 6
28 4 return $version->index;
29 }
30  
31  
32 0 ▶sub inspect {
Subroutine inspect: not called CC=1 SCAR=6.9
Pod documented
33 0 my ($self) = @_;
34 0 return $self->client->configs->inspect($self->id);
35 }
36  
37  
38 2 ▶sub update {
Subroutine update: called CC=2 SCAR=6.9
Pod documented
39 2 my ($self, %opts) = @_;
40 my $version
41 2 ▶ = exists $opts{version} ? delete $opts{version} : $self->version_index;
Branch: 1 branch
BranchTrueFalseTotal
exists $opts{'version'} ? : 1 1 2
42 2 return $self->client->configs->update($self->id, $version, %opts);
43 }
44  
45  
46 1 ▶sub remove {
Subroutine remove: called CC=1 SCAR=0.0
Pod documented
47 1 my ($self) = @_;
48 1 return $self->client->configs->remove($self->id);
49 }
50  
51  
52 # --- composition -----------------------------------------------------------
53 #
54 # Here rather than in API::Docker::API::Configs, for the reason spelled out in
55 # API::Docker::Role::Entity::Container: loading this role is what puts the
56 # methods on the class.
57 #
58 # The clash check is not decoration. Moo composes a role into a class the
59 # class-wins way, so a generated accessor of the same name as a method here
60 # would silently keep its place and the method would be missing -- and the
61 # generated classes are written from a specification that grows fields
62 # without asking. None of the five names collides today; a future one says so
63 # on the first `use`. `version_index` is the one to watch: the class already
64 # declares `version`.
65 {
66 52 my @provided = Package::Stash->new(__PACKAGE__)->list_all_symbols('CODE');
67 52 for my $class ('API::Docker::Type::Config') {
68 52 my $fields = $class->docker_attributes;
69 52 my @clash = sort grep { $fields->{$_} } @provided;
70 52 ▶ croak __PACKAGE__ . ': ' . $class . ' declares ' . join(', ', @clash)
Branch: 1 branch
BranchTrueFalseTotal
if @clash 0 52 52
71 . ' as a daemon field; the generated accessor would win over the '
72 . 'method of that name and it would be missing without a word'
73 if @clash;
74 52 Moo::Role->apply_roles_to_package($class, __PACKAGE__);
75 }
76 }
77  
78  
79 52 1;
80  
81 __END__
« Docker/API/Networks.pm ↑ Summary Docker/Role/Entity/Container.pm »