Docker/Type.pm

filter: Statementstmt 97.8% 182 / 186 Branchbran 83.9% 99 / 118 Conditioncond 65.7% 23 / 35 MC/DCmcdc 39.1% 9 / 23 Subroutinesub 100% 31 / 31 Podpod 100% 1 / 1 totaltotal 87.5% 345 / 394 CC 72 SCAR 20.8
CC
72
Cov
90%
_docker
15.5
_parse_type
14.1
_encode_value
12.2
CRAP 8.0
« Docker/API/Containers.pm ↑ Summary Docker/Role/Filters.pm »
1 package API::Docker::Type;
2 # ABSTRACT: The DSL and attribute registry behind the generated Docker types
3 56 our $VERSION = '0.005';
4 56 our %REGISTRY;
5 56 ▶use Moo ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 56 ▶use Moo::Role ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 56 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 56 ▶use Import::Into;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 56 ▶use Module::Runtime qw( use_module );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 56 ▶use Package::Stash;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 56 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 56 ▶use Types::Standard qw( Any ArrayRef Bool HashRef InstanceOf Int Maybe Num Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 56 ▶use API::Docker::Role::Type ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 56 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 56 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17  
18 56 my %SCALAR_TYPE = (
19 Str => Str,
20 Int => Int,
21 Num => Num,
22 Bool => Bool,
23 );
24  
25 # Names API::Docker::Role::Type already occupies. A generated attribute that
26 # collided with one of these would silently replace it, so it is refused
27 # instead -- the generator has to pick another Perl name and say so with an
28 # explicit `wire`.
29 56 my %RESERVED = map { ($_ => 1) } qw(
30 new BUILDARGS unknown_fields rejected_fields from_data from_json TO_JSON to_json
31 docker_attributes docker_attribute_order docker docker_extends
32 );
33  
34 4872 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
35 4872 my ($class) = @_;
36 4872 $class->_setup_class(scalar caller);
37 4872 return;
38 }
39  
40 # Per-class state that has to outlive the class's own compilation, because a
41 # generated class ends its body with `use namespace::clean`. That pragma takes
42 # a snapshot of the package's subs when it is reached and strips every one of
43 # them at the end of the class's compilation -- the imported Moo and type
44 # sugar, the two DSL keywords, AND anything a role composed at that point had
45 # already installed. Two consequences shape the setup below.
46 #
47 # has / extends -- The runtime `docker ...;` and `docker_extends ...;` lines
48 # fire after that cleanup, so by then `has` and `extends` are gone from the
49 # class and `$target->can('has')` returns undef. The `docker` keyword and
50 # the `Str`/`Int`/... it is handed survive the same cleanup only because
51 # Perl bound their CV into the call site at compile time; a name the DSL
52 # looks up by string at runtime has no such binding, so the two it resolves
53 # that way are captured here while they are still imported.
54 #
55 # the role -- API::Docker::Role::Type is NOT composed here. Composed at
56 # import (a BEGIN action) its methods and its two attributes would sit in
57 # namespace::clean's snapshot and be stripped with the sugar. So it is
58 # composed on the first `docker`/`docker_extends` call instead -- at
59 # runtime, after the cleanup, exactly as a `with 'Role'` line in a Moo
60 # class body would run. Every generated class issues at least one such
61 # call, and the composition lands before any object of the class is built.
62 56 my %CLASS_SUGAR;
63  
64 4872 ▶sub _setup_class {
Subroutine _setup_class: called CC=1 SCAR=0.0
65 4872 my ($class, $target) = @_;
66 4872 Moo->import::into($target);
67 4872 Types::Standard->import::into($target, qw( Any Bool Int Num Str ));
68 4872 $CLASS_SUGAR{$target} = {
69 has => $target->can('has'),
70 extends => $target->can('extends'),
71 };
72 4872 my $stash = Package::Stash->new($target);
73 4872 ▶ $stash->add_symbol('&docker' => sub { $class->_docker($target, @_) });
Subroutine __ANON__: called CC=1 SCAR=0.0
74 4872 ▶ $stash->add_symbol('&docker_extends' => sub { $class->_docker_extends($target, @_) });
Subroutine __ANON__: called CC=1 SCAR=0.0
75 4872 return;
76 }
77  
78 # Compose API::Docker::Role::Type once, on the first DSL call the class makes.
79 # Runtime, so it outlasts the class's `use namespace::clean`; idempotent, so
80 # the second and later DSL calls are a cheap flag check.
81 28734 ▶sub _ensure_role {
Subroutine _ensure_role: called CC=2 SCAR=6.9
82 28734 my ($target) = @_;
83 28734 ▶ return if $CLASS_SUGAR{$target}{role_composed};
Branch: 1 branch
BranchTrueFalseTotal
if $CLASS_SUGAR{$target}{"role_composed"} 23862 4872 28734
84 4872 $CLASS_SUGAR{$target}{role_composed} = 1;
85 4872 Moo::Role->apply_roles_to_package($target, 'API::Docker::Role::Type');
86 4872 return;
87 }
88  
89 # The one place a short class name becomes a full one. 'Mount' is
90 # API::Docker::Type::Mount; a name that already starts with the prefix is
91 # left alone; a leading + means "this is the full name, take it as it is".
92 # Docker's definitions are flat -- there are no groups to map, which is why
93 # there is no prefix table here and only this one rule.
94 5656 ▶sub _expand_class {
Subroutine _expand_class: called CC=3 SCAR=11.4
95 5656 my ($short) = @_;
96 5656 ▶ return substr($short, 1) if $short =~ /\A\+/;
Branch: 1 branch
BranchTrueFalseTotal
if $short =~ /\A\+/ 0 5656 5656
97 5656 ▶ return $short if $short =~ /\AAPI::Docker::Type::/;
Branch: 1 branch
BranchTrueFalseTotal
if $short =~ /\AAPI::Docker::Type::/ 0 5656 5656
98 5656 return 'API::Docker::Type::' . $short;
99 }
100  
101 # PortBindings <- port_bindings. One direction only; see the POD above.
102 24337 ▶sub _wire_from_perl {
Subroutine _wire_from_perl: called CC=1 SCAR=0.0
103 24337 my ($name) = @_;
104 24337 return join '', map { ucfirst } split /_/, $name;
105 }
106  
107 35989 ▶sub _is_type_tiny { return blessed($_[0]) && $_[0]->isa('Type::Tiny') }
Subroutine _is_type_tiny: called CC=2 SCAR=7.2
Condition66%2/3
builtin::blessed($_[0]) && $_[0]->isa('Type::Tiny')
!ll&&!rl&&r
12913023076
MC/DC50%1/2
builtin::blessed($_[0]) && $_[0]->isa('Type::Tiny')
builtin::blessed($_[0]) $_[0]->isa('Type::Tiny')
Truth table66%2/3
A && B
A= builtin::blessed($_[0])B= $_[0]->isa('Type::Tiny')
ABresult
0X0
100
111
108  
109 # A type spec becomes a descriptor, recursively:
110 # { kind => 'scalar', scalar => 'Str' }
111 # { kind => 'object', class => 'API::Docker::Type::PortBinding' }
112 # { kind => 'array', inner => <descriptor> }
113 # { kind => 'hash', inner => <descriptor> } keys are caller data
114 # { kind => 'any' }
115 # One recursive shape rather than a flag per combination, so { Str,
116 # ['PortBinding'] } and [[Str]] need no cases of their own anywhere.
117 35989 ▶sub _parse_type {
Subroutine _parse_type: called CC=12 SCAR=26.5
118 35989 my ($spec, $where) = @_;
119 35989 ▶ if (_is_type_tiny($spec)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_type_tiny($spec)) 23076 12913 35989
120 23076 my $name = $spec->name;
121 23076 ▶ return { kind => 'any' } if $name eq 'Any';
Branch: 1 branch
BranchTrueFalseTotal
if $name eq "Any" 340 22736 23076
122 22736 ▶ return { kind => 'scalar', scalar => $name } if $SCALAR_TYPE{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $SCALAR_TYPE{$name} 22736 0 22736
123 0 croak __PACKAGE__ . ": $where has unsupported type " . $name;
124 }
125 12913 ▶ if (ref $spec eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $spec eq "ARRAY") 5099 7814 12913
126 5099 ▶ croak __PACKAGE__ . ": $where is an array type with "
Branch: 1 branch
BranchTrueFalseTotal
unless @$spec == 1 0 5099 5099
127 . scalar(@$spec) . ' element types, it needs exactly one'
128 unless @$spec == 1;
129 5099 return { kind => 'array', inner => _parse_type($spec->[0], $where) };
130 }
131 7814 ▶ if (ref $spec eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $spec eq "HASH") 2216 5598 7814
132 2216 my @keys = keys %$spec;
133 2216 ▶ croak __PACKAGE__ . ": $where is a hash type; write it as { Str, \$value_type }"
Branch: 1 branch
BranchTrueFalseTotal
unless @keys == 1 and $keys[0] eq "Str" 0 2216 2216
Condition33%1/3
@keys == 1 and $keys[0] eq "Str"
!ll&&!rl&&r
002216
MC/DC0%0/2
@keys == 1 and $keys[0] eq "Str"
@keys == 1 $keys[0] eq "Str"
Truth table33%1/3
A and B
A= @keys == 1B= $keys[0] eq "Str"
ABresult
0X0
100
111
134 unless @keys == 1 && $keys[0] eq 'Str';
135 2216 return { kind => 'hash', inner => _parse_type($spec->{Str}, $where) };
136 }
137 5598 ▶ if (!ref $spec) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $spec) 5598 0 5598
138 5598 ▶ return { kind => 'any' } if $spec eq 'Any';
Branch: 1 branch
BranchTrueFalseTotal
if $spec eq "Any" 0 5598 5598
139 5598 ▶ return { kind => 'scalar', scalar => $spec } if $SCALAR_TYPE{$spec};
Branch: 1 branch
BranchTrueFalseTotal
if $SCALAR_TYPE{$spec} 0 5598 5598
140 5598 return { kind => 'object', class => _expand_class($spec) };
141 }
142 0 croak __PACKAGE__ . ": $where has an unreadable type spec (" . ref($spec) . ')';
143 }
144  
145  
146 7 ▶sub describe_type {
Subroutine describe_type: called CC=5 SCAR=16.2
Pod documented
147 7 my ($d) = @_;
148 7 my $kind = $d->{kind};
149 7 ▶ return lc $d->{scalar} if $kind eq 'scalar';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "scalar" 2 5 7
150 5 ▶ return 'object<' . $d->{class} . '>' if $kind eq 'object';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "object" 2 3 5
151 3 ▶ return 'array<' . describe_type($d->{inner}) . '>' if $kind eq 'array';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "array" 2 1 3
152 1 ▶ return 'hash<' . describe_type($d->{inner}) . '>' if $kind eq 'hash';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "hash" 1 0 1
153 0 return 'any';
154 }
155  
156 # Nothing is required, so every attribute is Maybe[...]. Hash values and
157 # array elements are Maybe[...] too: the daemon really does answer
158 # "2377/tcp": null inside a PortMap, and croaking while inflating a response
159 # we could otherwise use is not an improvement.
160 35989 ▶sub _isa_for {
Subroutine _isa_for: called CC=7 SCAR=19.5
161 35989 my ($d) = @_;
162 35989 my $kind = $d->{kind};
163 35989 ▶ return undef if $kind eq 'any';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "any" 340 35649 35989
164 35649 ▶ return $SCALAR_TYPE{ $d->{scalar} } if $kind eq 'scalar';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "scalar" 22736 12913 35649
165 12913 ▶ return InstanceOf[ $d->{class} ] if $kind eq 'object';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "object" 5598 7315 12913
166 7315 my $inner = _isa_for($d->{inner});
167 7315 ▶ return $kind eq 'array' ? ArrayRef : HashRef unless $inner;
Branch: 2 branches
BranchTrueFalseTotal
unless $inner 275 7040 7315
$kind eq 'array' ? : 0 275 275
168 7040 ▶ return $kind eq 'array' ? ArrayRef[ Maybe[$inner] ] : HashRef[ Maybe[$inner] ];
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'array' ? : 5099 1941 7040
169 }
170  
171 # The boolean normalisation, borrowed from IO::K8s::Resource (../io-k8s-p5),
172 # which documents the two traps: every reference is true in Perl, so \0 and a
173 # JSON::PP::Boolean have to be dereferenced rather than tested; and 'false'
174 # is a non-empty string and therefore true, so the strings are spelled out.
175 #
176 # undef stays undef rather than becoming 0. Docker tells an absent flag apart
177 # from a false one, TO_JSON omits undef, and "no value" must not turn into an
178 # explicit false on the wire.
179 334 ▶sub _normalize_bool {
Subroutine _normalize_bool: called CC=8 SCAR=20.8
180 334 my ($value) = @_;
181 334 ▶ if (ref $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value) 145 189 334
182 145 my $reftype = Scalar::Util::reftype($value);
183 145 ▶ croak __PACKAGE__ . ': a Bool wants a scalar or a scalar ref, got ' . $reftype
Branch: 1 branch
BranchTrueFalseTotal
unless $reftype eq "SCALAR" or $reftype eq "REF" 3 142 145
Condition66%2/3
$reftype eq "SCALAR" or $reftype eq "REF"
l!l&&r!l&&!r
14203
MC/DC50%1/2
$reftype eq "SCALAR" or $reftype eq "REF"
$reftype eq "SCALAR" $reftype eq "REF"
Truth table66%2/3
A or B
A= $reftype eq "SCALAR"B= $reftype eq "REF"
ABresult
1X1
011
000
184 unless $reftype eq 'SCALAR' || $reftype eq 'REF';
185 142 $value = $$value;
186 142 ▶ croak __PACKAGE__ . ': a Bool scalar ref dereferenced to another reference ('
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 0 142 142
187 . ref($value) . '), not a boolean' if ref $value;
188 }
189 331 ▶ return undef unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 8 323 331
190 323 ▶ return 0 if lc($value) eq 'false';
Branch: 1 branch
BranchTrueFalseTotal
if lc $value eq "false" 2 321 323
191 321 ▶ return $value ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 111 210 321
192 }
193  
194 # A hashref handed to an object-typed field is inflated the way the entry
195 # point that started the construction reads keys: through from_data while an
196 # engine response is being inflated, through new otherwise. So a nested
197 # literal in a request a caller assembled takes both spellings, and a nested
198 # object in a daemon response resolves wire names only -- the same
199 # distinction the two entry points draw at the top level, carried one level
200 # down. The class is loaded on first use rather than at declaration time: the
201 # registry is the only place its name appears, and loading it while the
202 # declaring class is still compiling would close a cycle the moment two
203 # definitions reference each other.
204 35989 ▶sub _coerce_for {
Subroutine _coerce_for: called CC=8 SCAR=20.8
205 35989 my ($d) = @_;
206 35989 my $kind = $d->{kind};
207 35989 ▶ return \&_normalize_bool if $kind eq 'scalar' && $d->{scalar} eq 'Bool';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "scalar" and $d->{"scalar"} eq "Bool" 2254 33735 35989
Condition100%3/3
$kind eq "scalar" and $d->{"scalar"} eq "Bool"
!ll&&!rl&&r
13253204822254
MC/DC100%2/2
$kind eq "scalar" and $d->{"scalar"} eq "Bool"
$kind eq "scalar" $d->{"scalar"} eq "Bool"
Truth table100%3/3
A and B
A= $kind eq "scalar"B= $d->{"scalar"} eq "Bool"
ABresult
0X0
100
111
208 33735 ▶ if ($kind eq 'object') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "object") 5598 28137 33735
209 5598 my $class = $d->{class};
210 5598 my $loaded;
211 403 ▶ return sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
212 403 my ($value) = @_;
213 403 ▶ return $value unless ref $value eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "HASH" 211 192 403
214 192 ▶ $loaded ||= use_module($class);
Condition66%2/3
$loaded ||= &use_module($class)
l!l&&r!l&&!r
781140
MC/DC0%0/2
$loaded ||= &use_module($class)
$loaded &use_module($class)
Truth table66%2/3
A ||= B
A= $loadedB= &use_module($class)
ABresult
1X1
011
000
215 192 ▶ return $API::Docker::Role::Type::RESPONSE
Branch: 1 branch
BranchTrueFalseTotal
$API::Docker::Role::Type::RESPONSE ? : 184 8 192
216 ? $class->from_data($value)
217 : $class->new(%$value);
218 5598 };
219 }
220 28137 ▶ my $inner = $kind eq 'array' || $kind eq 'hash' ? _coerce_for($d->{inner}) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'array' || $kind eq 'hash' ? : 7315 20822 28137
Condition100%3/3
$kind eq "array" or $kind eq "hash"
l!l&&r!l&&!r
5099221620822
MC/DC100%2/2
$kind eq "array" or $kind eq "hash"
$kind eq "array" $kind eq "hash"
Truth table100%3/3
A or B
A= $kind eq "array"B= $kind eq "hash"
ABresult
1X1
011
000
221 28137 ▶ return undef unless $inner;
Branch: 1 branch
BranchTrueFalseTotal
unless $inner 25945 2192 28137
222 148 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
223 148 my ($value) = @_;
224 148 ▶ return $value unless ref $value eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "ARRAY" 80 68 148
225 68 return [ map { $inner->($_) } @$value ];
226 2192 ▶ } if $kind eq 'array';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "array" 1846 346 2192
227 44 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
228 44 my ($value) = @_;
229 44 ▶ return $value unless ref $value eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "HASH" 0 44 44
230 # The keys are the caller's data: copied across, never touched.
231 44 return { map { ($_ => $inner->($value->{$_})) } keys %$value };
232 346 };
233 }
234  
235 # The serialisation half of a descriptor. Called by
236 # API::Docker::Role::Type::TO_JSON, which decides what to skip.
237 751 ▶sub _encode_value {
Subroutine _encode_value: called CC=12 SCAR=25.0
238 751 my ($d, $value) = @_;
239 751 ▶ return undef unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 2 749 751
240 749 my $kind = $d->{kind};
241 749 ▶ if ($kind eq 'scalar') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "scalar") 563 186 749
242 563 my $scalar = $d->{scalar};
243 563 ▶ return $value ? JSON::MaybeXS::true() : JSON::MaybeXS::false() if $scalar eq 'Bool';
Branch: 2 branches
BranchTrueFalseTotal
if $scalar eq "Bool" 78 485 563
$value ? : 31 47 78
244 485 ▶ return int($value) if $scalar eq 'Int';
Branch: 1 branch
BranchTrueFalseTotal
if $scalar eq "Int" 92 393 485
245 393 ▶ return 0 + $value if $scalar eq 'Num';
Branch: 1 branch
BranchTrueFalseTotal
if $scalar eq "Num" 0 393 393
246 393 return "$value";
247 }
248 186 ▶ return $value->TO_JSON if $kind eq 'object';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "object" 64 122 186
249 122 ▶ return [ map { _encode_value($d->{inner}, $_) } @$value ] if $kind eq 'array';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "array" 61 61 122
250 61 ▶ return { map { ($_ => _encode_value($d->{inner}, $value->{$_})) } keys %$value }
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "hash" 51 10 61
251 if $kind eq 'hash';
252 10 ▶ return [ @$value ] if ref $value eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "ARRAY" 0 10 10
253 10 ▶ return { %$value } if ref $value eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "HASH" 10 0 10
254 0 return $value;
255 }
256  
257 28676 ▶sub _docker {
Subroutine _docker: called CC=15 SCAR=27.4
258 28676 my ($class, $target, $name, $type_spec, %opt) = @_;
259 28676 _ensure_role($target);
260 28676 ▶ croak __PACKAGE__ . ": '$name' is not a snake_case attribute name"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and $name =~ /\A[a-z][a-z0-9_]*\z/ 0 28676 28676
Condition33%1/3
defined $name and $name =~ /\A[a-z][a-z0-9_]*\z/
!ll&&!rl&&r
0028676
MC/DC0%0/2
defined $name and $name =~ /\A[a-z][a-z0-9_]*\z/
defined $name $name =~ /\A[a-z][a-z0-9_]*\z/
Truth table33%1/3
A and B
A= defined $nameB= $name =~ /\A[a-z][a-z0-9_]*\z/
ABresult
0X0
100
111
261 unless defined $name && $name =~ /\A[a-z][a-z0-9_]*\z/;
262 croak __PACKAGE__ . ": '$name' in $target is a name this role already uses"
263 28676 ▶ if $RESERVED{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $RESERVED{$name} 0 28676 28676
264 croak __PACKAGE__ . ": '$name' is declared twice in $target"
265 28676 ▶ if $REGISTRY{$target} && $REGISTRY{$target}{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $REGISTRY{$target} and $REGISTRY{$target}{$name} 1 28675 28676
Condition100%3/3
$REGISTRY{$target} and $REGISTRY{$target}{$name}
!ll&&!rl&&r
4872238031
MC/DC100%2/2
$REGISTRY{$target} and $REGISTRY{$target}{$name}
$REGISTRY{$target} $REGISTRY{$target}{$name}
Truth table100%3/3
A and B
A= $REGISTRY{$target}B= $REGISTRY{$target}{$name}
ABresult
0X0
100
111
266  
267 28675 ▶ my $wire = delete $opt{wire} // _wire_from_perl($name);
Condition66%2/3
delete $opt{"wire"} // _wire_from_perl($name)
l!l&&r!l&&!r
4338243370
MC/DC0%0/2
delete $opt{"wire"} // _wire_from_perl($name)
delete $opt{"wire"} _wire_from_perl($name)
Truth table66%2/3
A // B
A= delete $opt{"wire"}B= _wire_from_perl($name)
ABresult
1X1
011
000
268 # The Perl-name guard above has a twin: _docker_wire_index maps a wire name
269 # to one Perl name, so a second field claiming a wire name would make the
270 # first unreachable on inflation while TO_JSON wrote both to that one key.
271 # None of the 201 generated classes does this; the generator could emit it
272 # the day a hand-picked `wire` collides with a derived one (karr k85).
273 28675 ▶ if (my ($taken) = sort grep { $REGISTRY{$target}{$_}{wire} eq $wire }
Branch: 1 branch
BranchTrueFalseTotal
if (my($taken) = sort(grep({$REGISTRY{$target}{$_}{"wire"} eq $wire;} keys %{$REGISTRY{$target} or {};}))) 1 28674 28675
274 28675 ▶ keys %{ $REGISTRY{$target} || {} }) {
Condition100%2/2
$REGISTRY{$target} || {}
l!l
238034872
MC/DC100%1/1
$REGISTRY{$target} || {}
$REGISTRY{$target}
Truth table100%2/2
A
A= $REGISTRY{$target}
Aresult
11
00
275 1 croak __PACKAGE__ . ": '$name' in $target asks for the wire name "
276 . "'$wire', which '$taken' already has";
277 }
278 28674 my $since = delete $opt{since};
279 28674 my $enum = delete $opt{enum};
280 28674 ▶ my $required = delete $opt{required} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
delete $opt{'required'} ? : 2601 26073 28674
281 28674 ▶ croak __PACKAGE__ . ": '$name' in $target got unknown option(s): "
Branch: 1 branch
BranchTrueFalseTotal
if %opt 0 28674 28674
282 . join(', ', sort keys %opt) if %opt;
283  
284 28674 my $descriptor = _parse_type($type_spec, "$target\::$name");
285 28674 my $isa = _isa_for($descriptor);
286 28674 my $coerce = _coerce_for($descriptor);
287 28674 ▶ $REGISTRY{$target}{$name} = {
Branch: 1 branch
BranchTrueFalseTotal
$isa ? : 28609 65 28674
288 name => $name,
289 wire => $wire,
290 type => $descriptor,
291 since => $since,
292 enum => $enum,
293 required => $required,
294 # The same two the Moo attribute below is given, kept so the response
295 # path can ask whether a value fits before handing it to the constructor
296 # rather than finding out by being croaked at (karr k83).
297 isa => $isa ? Maybe[$isa] : undef,
298 coerce => $coerce,
299 };
300 {
301 56 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
302 28674 push @{"${target}::_docker_attr_order"}, $name;
303 }
304 28674 API::Docker::Role::Type::_invalidate_docker_cache($target);
305  
306 28674 ▶ my $has = $CLASS_SUGAR{$target}{has} // $target->can('has');
Condition33%1/3
$CLASS_SUGAR{$target}{"has"} // $target->can("has")
l!l&&r!l&&!r
2867400
MC/DC0%0/2
$CLASS_SUGAR{$target}{"has"} // $target->can("has")
$CLASS_SUGAR{$target}{"has"} $target->can("has")
Truth table33%1/3
A // B
A= $CLASS_SUGAR{$target}{"has"}B= $target->can("has")
ABresult
1X1
011
000
307 28674 my $info = $REGISTRY{$target}{$name};
308 $has->($name,
309 is => 'rw',
310 ($info->{isa} ? (isa => $info->{isa}) : ()),
311 28674 ▶ ($info->{coerce} ? (coerce => $info->{coerce}) : ()),
Branch: 2 branches
BranchTrueFalseTotal
$info->{'isa'} ? : 28609 65 28674
$info->{'coerce'} ? : 7852 20822 28674
312 );
313 28674 return;
314 }
315  
316 58 ▶sub _docker_extends {
Subroutine _docker_extends: called CC=3 SCAR=11.3
317 58 my ($class, $target, @parents) = @_;
318 58 _ensure_role($target);
319 58 ▶ croak __PACKAGE__ . ": docker_extends in $target needs at least one class"
Branch: 1 branch
BranchTrueFalseTotal
unless @parents 0 58 58
320 unless @parents;
321 58 my @full = map { use_module(_expand_class($_)) } @parents;
322 58 ▶ my $extends = $CLASS_SUGAR{$target}{extends} // $target->can('extends');
Condition33%1/3
$CLASS_SUGAR{$target}{"extends"} // $target->can("extends")
l!l&&r!l&&!r
5800
MC/DC0%0/2
$CLASS_SUGAR{$target}{"extends"} // $target->can("extends")
$CLASS_SUGAR{$target}{"extends"} $target->can("extends")
Truth table33%1/3
A // B
A= $CLASS_SUGAR{$target}{"extends"}B= $target->can("extends")
ABresult
1X1
011
000
323 58 $extends->(@full);
324 58 API::Docker::Role::Type::_invalidate_docker_cache($target);
325 58 return;
326 }
327  
328 56 1;
329  
330 __END__
« Docker/API/Containers.pm ↑ Summary Docker/Role/Filters.pm »