Docker/Role/Entity/Secret.pm

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