Zydeco.pm

filter: Statementstmt 86.7% 808 / 931 Branchbran 64.0% 346 / 540 Conditioncond 58.7% 104 / 177 MC/DCmcdc 29.5% 31 / 105 Subroutinesub 92.6% 113 / 122 Podpod 66.6% 4 / 6 totaltotal 74.7% 1406 / 1881 SCAR 76.6
CC
364
Cov
76%
import
67.4
_handle_signature_list
54.2
__ANON__
43.1
CRAP 2120.0
↑ Summary MooX/Pression.pm »
1 53 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 53 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 41 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 39 ▶use B ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 36 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 36 ▶use Import::Into ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 33 ▶use MooX::Press 0.048 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 32 ▶use MooX::Press::Keywords ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 32 ▶use Syntax::Keyword::Try ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 32 ▶use feature ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 package Zydeco;
13  
14 31 our $AUTHORITY = 'cpan:TOBYINK';
15 31 our $VERSION = '0.616';
16  
17 32 ▶use Keyword::Simple ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18 32 ▶use PPR;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 32 ▶use B::Hooks::EndOfScope;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 32 ▶use Exporter::Shiny our @EXPORT = qw( version authority overload );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 32 ▶use Devel::StrictMode qw(STRICT);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 32 ▶use Types::Standard qw( is_HashRef is_CodeRef is_Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 my $decomment = sub {
25 1 ▶ require Carp;
Subroutine __ANON__: called CC=1 SCAR=0.0
26 1 Carp::carp("Cannot remove comments within a type constraint; please upgrade perl");
27 1 return $_[0];
28 31 };
29 31 ▶$decomment = \&PPR::decomment if $] >= 5.016;
Branch: 1 branch
BranchTrueFalseTotal
if $] >= "5.016" 31 0 31
30  
31 BEGIN {
32 package Zydeco::_Gather;
33 32 ▶ my %gather;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 my %stack;
35 sub _already {
36 40 ▶ my ($me, $caller) = @_;
Subroutine _already: called CC=1 SCAR=0.0
37 40 !!$gather{$me}{$caller};
38 }
39 sub _predeclare {
40 92 ▶ my ($me, $opts, $kind, $pkg, $pkgopts) = @_;
Subroutine _predeclare: called CC=7 SCAR=19.9
41 # Figure out type name
42 92 ▶ return if $kind =~ /role_generator/;
Branch: 1 branch
BranchTrueFalseTotal
if $kind =~ /role_generator/u 4 87 91
43 88 my %opts = (%$opts, %$pkgopts);
44 88 ▶ my $qname = 'MooX::Press'->qualify_name($pkg, $opts{'prefix'}, $opts{'extends'}//$opts{'_stack'}[-1]);
Condition100%3/3
$opts{"extends"} // $opts{"_stack"}[-1]
l!l&&r!l&&!r
92553
MC/DC100%2/2
$opts{"extends"} // $opts{"_stack"}[-1]
$opts{"extends"} $opts{"_stack"}[-1]
Truth table100%3/3
A // B
A= $opts{"extends"}B= $opts{"_stack"}[-1]
ABresult
1X1
011
000
45
46 88 ▶ if ($kind =~ /class_generator/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind =~ /class_generator/u) { } 4 83 87
47 my $typename1 = $opts{'class_type_name'}
48 5 ▶ || sprintf('%sClass', 'MooX::Press'->type_name($qname, $opts{'prefix'}));
Condition33%1/3
$opts{'class_type_name'} || sprintf('%sClass', 'MooX::Press'->type_name($qname, $opts{'prefix'}))
l!l&&r!l&&!r
040
MC/DC0%0/2
$opts{'class_type_name'} || sprintf('%sClass', 'MooX::Press'->type_name($qname, $opts{'prefix'}))
$opts{'class_type_name'} sprintf('%sClass', 'MooX::Press'->type_name($qname, $opts{'prefix'}))
Truth table33%1/3
A || B
A= $opts{'class_type_name'}B= sprintf('%sClass', 'MooX::Press'->type_name($qname, $opts{'prefix'}))
ABresult
1X1
011
000
49 my $typename2 = $opts{'instance_type_name'}
50 4 ▶ || sprintf('%sInstance', 'MooX::Press'->type_name($qname, $opts{'prefix'}));
Condition33%1/3
$opts{'instance_type_name'} || sprintf('%sInstance', 'MooX::Press'->type_name($qname, $opts{'prefix'}))
l!l&&r!l&&!r
040
MC/DC0%0/2
$opts{'instance_type_name'} || sprintf('%sInstance', 'MooX::Press'->type_name($qname, $opts{'prefix'}))
$opts{'instance_type_name'} sprintf('%sInstance', 'MooX::Press'->type_name($qname, $opts{'prefix'}))
Truth table33%1/3
A || B
A= $opts{'instance_type_name'}B= sprintf('%sInstance', 'MooX::Press'->type_name($qname, $opts{'prefix'}))
ABresult
1X1
011
000
51 4 'Zydeco'->_predeclare($opts{'caller'}, $opts{'type_library'}, $typename1, $typename2);
52 }
53 else {
54 83 ▶ my $typename = $opts{'type_name'} || 'MooX::Press'->type_name($qname, $opts{'prefix'});
Condition66%2/3
$opts{'type_name'} || 'MooX::Press'->type_name($qname, $opts{'prefix'})
l!l&&r!l&&!r
1820
MC/DC0%0/2
$opts{'type_name'} || 'MooX::Press'->type_name($qname, $opts{'prefix'})
$opts{'type_name'} 'MooX::Press'->type_name($qname, $opts{'prefix'})
Truth table66%2/3
A || B
A= $opts{'type_name'}B= 'MooX::Press'->type_name($qname, $opts{'prefix'})
ABresult
1X1
011
000
55 83 'Zydeco'->_predeclare($opts{'caller'}, $opts{'type_library'}, $typename);
56 }
57 }
58 sub import {
59 351 ▶ my ($me, $action, $caller) = (shift, shift, scalar caller);
Subroutine import: called CC=19 SCAR=31.3
60 351 ▶ if ($action eq -gather) {
Branch: 4 branches
BranchTrueFalseTotal
if ($action eq '-gather') { } 130 221 351
elsif ($action eq '-go') { } 39 182 221
elsif ($action eq '-parent') { } 91 91 182
elsif ($action eq '-unparent') { } 91 0 91
61 130 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 403 130 533
62 403 my ($k, $v) = splice @_, 0, 2;
63 403 ▶ if (my ($kind,$pkg) = ($k =~ /^(class|role|class_generator|role_generator):(.+)$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $k =~ /^(class|role|class_generator|role_generator):(.+)$/u) { } 91 312 403
64 91 ▶ if ( my @stack = @{ $stack{$me}{$caller}||[] } ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my(@stack) = @{$stack{$me}{$caller} or [];}) 91 0 91
$stack{$me}{$caller} or [] 0 91 91
65 91 ▶ pop @stack if $stack[-1] eq $pkg;
Branch: 1 branch
BranchTrueFalseTotal
if $stack[-1] eq $pkg 91 0 91
66 91 ▶ if (@stack) {
Branch: 1 branch
BranchTrueFalseTotal
if (@stack) 25 66 91
67 25 $v->{_stack} = \@stack;
68 25 $kind = '_defer_'.$kind;
69 }
70 }
71 91 ▶ push @{ $gather{$me}{$caller}{$kind}||=[] }, $pkg, $v;
Condition100%2/2
$gather{$me}{$caller}{$kind} ||= []
l!l
3952
MC/DC100%1/1
$gather{$me}{$caller}{$kind} ||= []
$gather{$me}{$caller}{$kind}
Truth table100%2/2
A
A= $gather{$me}{$caller}{$kind}
Aresult
11
00
72 91 $me->_predeclare( $gather{$me}{$caller}, $kind, $pkg, $v );
73 }
74 else {
75 312 $gather{$me}{$caller}{$k} = $v;
76 }
77 }
78 }
79 elsif ($action eq -go) {
80 39 ▶ if ($gather{$me}{$caller}{'_defer_role'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gather{$me}{$caller}{"_defer_role"}) 0 39 39
81 0 require Carp;
82 0 Carp::croak('Nested roles are not supported');
83 }
84 39 ▶ if ($gather{$me}{$caller}{'_defer_role_generator'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gather{$me}{$caller}{"_defer_role_generator"}) 0 39 39
85 0 require Carp;
86 0 Carp::croak('Nested role generators are not supported');
87 }
88 39 ▶ if ($gather{$me}{$caller}{'_defer_class_generator'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gather{$me}{$caller}{"_defer_class_generator"}) 1 38 39
89 1 ▶ $me->_undefer_class_generators($gather{$me}{$caller}{'class_generator'}||=[], delete $gather{$me}{$caller}{'_defer_class_generator'});
Condition50%1/2
$gather{$me}{$caller}{"class_generator"} ||= []
l!l
01
MC/DC0%0/1
$gather{$me}{$caller}{"class_generator"} ||= []
$gather{$me}{$caller}{"class_generator"}
Truth table50%1/2
A
A= $gather{$me}{$caller}{"class_generator"}
Aresult
11
00
90 }
91 39 ▶ if ($gather{$me}{$caller}{'_defer_class'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gather{$me}{$caller}{"_defer_class"}) 5 34 39
92 5 $me->_undefer_classes($gather{$me}{$caller}{'class'}, delete $gather{$me}{$caller}{'_defer_class'});
93 }
94
95 36 ▶ if ($gather{$me}{$caller}{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gather{$me}{$caller}{"debug"}) 0 36 36
96 0 require Data::Dumper;
97 0 local $Data::Dumper::Deparse = 1;
98 0 warn Data::Dumper::Dumper($gather{$me}{$caller});
99 }
100
101 36 delete $stack{$me}{$caller};
102 36 @_ = ('MooX::Press' => delete $gather{$me}{$caller});
103 36 goto \&MooX::Press::import;
104 }
105 elsif ($action eq -parent) {
106 91 ▶ push @{ $stack{$me}{$caller}||=[] }, $_[0];
Condition100%2/2
$stack{$me}{$caller} ||= []
l!l
5437
MC/DC100%1/1
$stack{$me}{$caller} ||= []
$stack{$me}{$caller}
Truth table100%2/2
A
A= $stack{$me}{$caller}
Aresult
11
00
107 }
108 elsif ($action eq -unparent) {
109 91 pop @{ $stack{$me}{$caller} };
110 }
111 else {
112 0 die;
113 }
114 }
115 sub _undefer_classes {
116 5 ▶ my ($me, $classes, $d) = @_;
Subroutine _undefer_classes: called CC=10 SCAR=23.0
117 5 ▶ my %class_hash = @{$classes||[]};
Branch: 1 branch
BranchTrueFalseTotal
$classes or [] 3 2 5
118 5 my @deferred;
119 5 my $max_depth = 0;
120 5 ▶ while (@$d) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$d) 24 5 29
121 24 my ($class, $spec) = splice(@$d, 0, 2);
122 24 $spec->{_class_name} = $class;
123 24 $spec->{_depth} = @{ $spec->{_stack} };
124 24 push @deferred, $spec;
125 24 ▶ $max_depth = $spec->{_depth} if $spec->{_depth} > $max_depth;
Branch: 1 branch
BranchTrueFalseTotal
if $spec->{"_depth"} > $max_depth 7 17 24
126 }
127 5 DEPTH: for my $depth (1 .. $max_depth) {
128 8 SPEC: for my $spec (@deferred) {
129 84 ▶ next SPEC unless $spec->{_depth} == $depth;
Branch: 1 branch
BranchTrueFalseTotal
unless $spec->{"_depth"} == $depth 60 24 84
130 24 my $parent_key = join('|', @{$spec->{_stack}});
131 24 my $my_key = join('|', @{$spec->{_stack}}, $spec->{_class_name});
132 24 ▶ if (not $class_hash{$parent_key}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class_hash{$parent_key}) 3 21 24
133 3 require Carp;
134 Carp::croak(sprintf(
135 '%s is nested in %s but %s is not a class',
136 $spec->{_class_name},
137 $spec->{_stack}[-1],
138 3 $spec->{_stack}[-1],
139 ));
140 }
141 21 ▶ push @{ $class_hash{$parent_key}{subclass} ||=[] }, $spec->{_class_name}, $spec;
Condition100%2/2
$class_hash{$parent_key}{"subclass"} ||= []
l!l
138
MC/DC100%1/1
$class_hash{$parent_key}{"subclass"} ||= []
$class_hash{$parent_key}{"subclass"}
Truth table100%2/2
A
A= $class_hash{$parent_key}{"subclass"}
Aresult
11
00
142 21 $class_hash{$my_key} = $spec;
143 }
144 }
145 2 for my $spec (@deferred) {
146 21 delete $spec->{_stack};
147 21 delete $spec->{_class_name};
148 21 delete $spec->{_depth};
149 }
150 }
151 sub _undefer_class_generators {
152 1 ▶ my ($me, $classes, $d) = @_;
Subroutine _undefer_class_generators: called CC=2 SCAR=6.9
153 1 ▶ while (@$d) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$d) 1 1 2
154 1 my ($class, $spec) = splice(@$d, 0, 2);
155 1 my $extends = $spec->{_stack}[-1];
156 1 my $next = delete($spec->{code});
157 $spec->{code} = sub {
158 2 ▶ my $got = $next->(@_);
Subroutine __ANON__: called CC=2 SCAR=7.1
159 2 ▶ $got->{extends} ||= [$extends];
Condition50%1/2
$got->{"extends"} ||= [$extends]
l!l
02
MC/DC0%0/1
$got->{"extends"} ||= [$extends]
$got->{"extends"}
Truth table50%1/2
A
A= $got->{"extends"}
Aresult
11
00
160 2 $got;
161 1 };
162 1 delete $spec->{_stack};
163 1 push @$classes, $class, $spec;
164 }
165 }
166  
167 32 $INC{'Zydeco/_Gather.pm'} = __FILE__;
168 };
169  
170 #
171 # GRAMMAR
172 #
173  
174 31 our $GRAMMAR = qr{
175 (?(DEFINE)
176
177 (?<PerlKeyword>
178
179 (?: include (?&MxpIncludeSyntax) )|
180 (?: class (?&MxpClassSyntax) )|
181 (?: abstract (?&MxpAbstractSyntax) )|
182 (?: role (?&MxpRoleSyntax) )|
183 (?: interface (?&MxpRoleSyntax) )|
184 (?: toolkit (?&MxpToolkitSyntax) )|
185 (?: begin (?&MxpHookSyntax) )|
186 (?: end (?&MxpHookSyntax) )|
187 (?: after_apply (?&MxpHookSyntax) )|
188 (?: before_apply (?&MxpHookSyntax) )|
189 (?: type_name (?&MxpTypeNameSyntax) )|
190 (?: extends (?&MxpExtendsSyntax) )|
191 (?: with (?&MxpWithSyntax) )|
192 (?: requires (?&MxpWithSyntax) )|
193 (?: (?:has|field|param) (?&MxpHasSyntax) )|
194 (?: constant (?&MxpConstantSyntax) )|
195 (?: coerce (?&MxpCoerceSyntax) )|
196 (?: method (?&MxpMethodSyntax) )|
197 (?: factory (?&MxpFactorySyntax) )|
198 (?: factory (?&MxpFactoryViaSyntax))|
199 (?: symmethod (?&MxpSymMethodSyntax) )|
200 (?: before (?&MxpModifierSyntax) )|
201 (?: after (?&MxpModifierSyntax) )|
202 (?: around (?&MxpModifierSyntax) )|
203 (?: multi (?&MxpMultiSyntax) )|
204 (?: try (?&TrySyntax) )
205 )#</PerlKeyword>
206
207 (?<MxpSimpleIdentifier>
208
209 (?&PerlIdentifier)|(?&PerlBlock)
210 )#</MxpSimpleIdentifier>
211
212 (?<MxpSimpleIdentifiers>
213
214 (?&MxpSimpleIdentifier)
215 (?:
216 (?&PerlOWS)
217 ,
218 (?&PerlOWS)
219 (?&MxpSimpleIdentifier)
220 )*
221 )#</MxpSimpleIdentifiers>
222
223 (?<MxpDecoratedIdentifier>
224
225 (?: \+ )? # CAPTURE:plus
226 (?: \* | \$ )? # CAPTURE:asterisk
227 (?: (?&MxpSimpleIdentifier) ) # CAPTURE:name
228 (?: \! | \? )? # CAPTURE:postfix
229 )#</MxpDecoratedIdentifier>
230
231 (?<MxpDecoratedIdentifierSolo>
232 (?: (?&MxpDecoratedIdentifier) ) # deliberately non-capturing
233 )#</MxpDecoratedIdentifierSolo>
234
235 (?<MxpDecoratedIdentifiers>
236
237 (?&MxpDecoratedIdentifier)
238 (?:
239 (?&PerlOWS)
240 ,
241 (?&PerlOWS)
242 (?&MxpDecoratedIdentifier)
243 )*
244 )#</MxpDecoratedIdentifiers>
245
246 (?<MxpSimpleTypeSpec>
247
248 ~?(?&PerlBareword)(?&PerlAnonymousArray)?
249 )#</MxpSimpleTypeSpec>
250
251 (?<MxpTypeSpec>
252
253 (?&MxpSimpleTypeSpec)
254 (?:
255 (?&PerlOWS) \& (?&PerlOWS)
256 (?&MxpSimpleTypeSpec)
257 )*
258 (?:
259 (?&PerlOWS) \| (?&PerlOWS)
260 (?&MxpSimpleTypeSpec)
261 (?:
262 (?&PerlOWS) \& (?&PerlOWS)
263 (?&MxpSimpleTypeSpec)
264 )*
265 )*
266 )#</MxpTypeSpec>
267
268 (?<MxpExtendedTypeSpec>
269
270 (?&MxpTypeSpec)|(?&PerlBlock)
271 )#</MxpExtendedTypeSpec>
272
273 (?<MxpSignatureVariable>
274 [\$\@\%]
275 (?&PerlIdentifier)
276 )#</MxpSignatureVariable>
277
278 (?<MxpSignatureElement>
279
280 (?&PerlOWS)
281 (?: (?&MxpExtendedTypeSpec))? # CAPTURE:type
282 (?&PerlOWS)
283 (?: # CAPTURE:name
284 (?&MxpSignatureVariable) | (\*(?&PerlIdentifier) | [\$\@\%] )
285 )
286 (?: # CAPTURE:postamble
287 \? | ((?&PerlOWS)=(?&PerlOWS)(?&PerlScalarExpression))
288 )?
289 )#</MxpSignatureElement>
290
291 (?<MxpSignatureList>
292
293 (?&MxpSignatureElement)
294 (?:
295 (?&PerlOWS)
296 ,
297 (?&PerlOWS)
298 (?&MxpSignatureElement)
299 )*
300 )#</MxpSignatureList>
301
302 (?<MxpAttribute>
303
304 :
305 [^\W0-9]\w*
306 (?:
307 [(]
308 [^\)]+
309 [)]
310 )?
311 )#</MxpAttribute>
312
313 (?<MxpRoleList>
314
315 (?&PerlOWS)
316 (?:
317 (?&PerlBlock) | (?&PerlQualifiedIdentifier)
318 )
319 (?:
320 (?:\s*\?) | (?: (?&PerlOWS) [(] (?&PerlOWS) (?&PerlList) (?&PerlOWS) [)] )
321 )?
322 (?:
323 (?&PerlOWS)
324 ,
325 (?&PerlOWS)
326 (?:
327 (?&PerlBlock) | (?&PerlQualifiedIdentifier)
328 )
329 (?:
330 (?:\s*\?) | (?: (?&PerlOWS) [(] (?&PerlOWS) (?&PerlList) (?&PerlOWS) [)] )
331 )?
332 )*
333 )#</MxpRoleList>
334
335 (?<MxpCompactRoleList>
336
337 (?&PerlOWS)
338 (?:
339 (?&PerlQualifiedIdentifier)
340 )
341 (?:
342 (?:\s*\?) | (?: (?&PerlOWS) [(] (?&PerlOWS) (?&PerlList) (?&PerlOWS) [)] )
343 )?
344 (?:
345 (?&PerlOWS)
346 ,
347 (?&PerlOWS)
348 (?:
349 (?&PerlQualifiedIdentifier)
350 )
351 (?:
352 (?:\s*\?) | (?: (?&PerlOWS) [(] (?&PerlOWS) (?&PerlList) (?&PerlOWS) [)] )
353 )?
354 )*
355 )#</MxpCompactRoleList>
356
357 (?<MxpBlockLike>
358
359 (?: (?&PerlBlock) ) |
360 (?: [=] (?&PerlOWS) (?&PerlScalarExpression) (?&PerlOWS) [;] )
361 )#</MxpBlockLike>
362
363 (?<MxpIncludeSyntax>
364
365 (?&PerlOWS)
366 (?: (?&PerlQualifiedIdentifier) )? # CAPTURE:name
367 (?&PerlOWS)
368 )#</MxpIncludeSyntax>
369
370 (?<MxpClassSyntax>
371
372 (?&PerlOWS)
373 (?: [+] )? # CAPTURE:plus
374 (?: (?&PerlQualifiedIdentifier) )? # CAPTURE:name
375 (?&PerlOWS)
376 (?:
377 (?: (?&PerlVersionNumber) ) # CAPTURE:version
378 (?&PerlOWS)
379 )?
380 (?:
381 [(]
382 (?&PerlOWS)
383 (?: # CAPTURE:sig
384 (?&MxpSignatureList)?
385 )
386 (?&PerlOWS)
387 [)]
388 )?
389 (?&PerlOWS)
390 (?:
391 (?: extends | isa | is )
392 (?&PerlOWS)
393 (?: (?&MxpCompactRoleList) ) # CAPTURE:compact_extends
394 (?&PerlOWS)
395 )?
396 (?:
397 (?: with | does )
398 (?&PerlOWS)
399 (?: (?&MxpCompactRoleList) ) # CAPTURE:compact_with
400 (?&PerlOWS)
401 )?
402 (?: (?&PerlBlock) )? # CAPTURE:block
403 (?&PerlOWS)
404 )#</MxpClassSyntax>
405
406 (?<MxpAbstractSyntax>
407
408 (?&PerlOWS)
409 class
410 (?&PerlOWS)
411 (?: [+] )? # CAPTURE:plus
412 (?: (?&PerlQualifiedIdentifier) )? # CAPTURE:name
413 (?&PerlOWS)
414 (?:
415 (?: (?&PerlVersionNumber) ) # CAPTURE:version
416 (?&PerlOWS)
417 )?
418 (?:
419 [(]
420 (?&PerlOWS)
421 (?: # CAPTURE:sig
422 (?&MxpSignatureList)?
423 )
424 (?&PerlOWS)
425 [)]
426 )?
427 (?&PerlOWS)
428 (?:
429 (?: extends | isa | is )
430 (?&PerlOWS)
431 (?: (?&MxpCompactRoleList) ) # CAPTURE:compact_extends
432 (?&PerlOWS)
433 )?
434 (?:
435 (?: with | does )
436 (?&PerlOWS)
437 (?: (?&MxpCompactRoleList) ) # CAPTURE:compact_with
438 (?&PerlOWS)
439 )?
440 (?: (?&PerlBlock) )? # CAPTURE:block
441 (?&PerlOWS)
442 )#</MxpAbstractSyntax>
443
444 (?<MxpRoleSyntax>
445
446 (?&PerlOWS)
447 (?: (?&PerlQualifiedIdentifier) )? # CAPTURE:name
448 (?&PerlOWS)
449 (?:
450 (?: (?&PerlVersionNumber) ) # CAPTURE:version
451 (?&PerlOWS)
452 )?
453 (?:
454 [(]
455 (?&PerlOWS)
456 (?: # CAPTURE:sig
457 (?&MxpSignatureList)?
458 )
459 (?&PerlOWS)
460 [)]
461 )?
462 (?&PerlOWS)
463 (?:
464 (?: with | does )
465 (?&PerlOWS)
466 (?: (?&MxpCompactRoleList) ) # CAPTURE:compact_with
467 (?&PerlOWS)
468 )?
469 (?: (?&PerlBlock) )? # CAPTURE:block
470 (?&PerlOWS)
471 )#</MxpRoleSyntax>
472
473 (?<MxpHookSyntax>
474
475 (?&PerlOWS)
476 (?: (?&PerlBlock) ) # CAPTURE:hook
477 (?&PerlOWS)
478 )#</MxpHookSyntax>
479
480 (?<MxpTypeNameSyntax>
481
482 (?&PerlOWS)
483 (?: (?&PerlIdentifier) ) # CAPTURE:name
484 (?&PerlOWS)
485 )#</MxpTypeNameSyntax>
486
487 (?<MxpToolkitSyntax>
488
489 (?&PerlOWS)
490 (?: (?&PerlIdentifier) ) # CAPTURE:name
491 (?&PerlOWS)
492 (?:
493 [(]
494 (?&PerlOWS)
495 (?: # CAPTURE:imports
496 (?: (?&PerlQualifiedIdentifier)|(?&PerlComma)|(?&PerlOWS) )*
497 )
498 (?&PerlOWS)
499 [)]
500 )?
501 (?&PerlOWS)
502 )#</MxpToolkitSyntax>
503
504 (?<MxpExtendsSyntax>
505
506 (?&PerlOWS)
507 (?: # CAPTURE:list
508 (?&MxpRoleList)
509 )
510 (?&PerlOWS)
511 )#</MxpExtendsSyntax>
512
513 (?<MxpWithSyntax>
514
515 (?&PerlOWS)
516 (?: # CAPTURE:list
517 (?&MxpRoleList)
518 )
519 (?&PerlOWS)
520 )#</MxpWithSyntax>
521
522 (?<MxpRequiresSyntax>
523
524 (?&PerlOWS)
525 (?: (?&MxpSimpleIdentifier) ) # CAPTURE:name
526 (?&PerlOWS)
527 (?:
528 [(]
529 (?&PerlOWS)
530 (?: # CAPTURE:sig
531 (?&MxpSignatureList)?
532 )
533 (?&PerlOWS)
534 [)]
535 )?
536 (?&PerlOWS)
537 )#</MxpRequiresSyntax>
538
539 (?<MxpHasSyntax>
540
541 (?&PerlOWS)
542 (?: (?&MxpDecoratedIdentifiers) ) # CAPTURE:name
543 (?&PerlOWS)
544 (?:
545 [(]
546 (?&PerlOWS)
547 (?: (?&PerlList) ) # CAPTURE:spec
548 (?&PerlOWS)
549 [)]
550 )?
551 (?&PerlOWS)
552 (?:
553 [=]
554 (?&PerlOWS)
555 (?: (?&PerlAssignment) ) # CAPTURE:default
556 )?
557 (?&PerlOWS)
558 )#</MxpHasSyntax>
559
560 (?<MxpConstantSyntax>
561
562 (?&PerlOWS)
563 (?: (?&PerlIdentifier) ) # CAPTURE:name
564 (?&PerlOWS)
565 =
566 (?&PerlOWS)
567 (?: (?&PerlExpression) ) # CAPTURE:expr
568 (?&PerlOWS)
569 )#</MxpConstantSyntax>
570
571 (?<MxpMethodSyntax>
572
573 (?&PerlOWS)
574 (?: \$? (?&MxpSimpleIdentifier) )? # CAPTURE:name
575 (?&PerlOWS)
576 (?: ( (?&MxpAttribute) (?&PerlOWS) )+ )? # CAPTURE:attributes
577 (?&PerlOWS)
578 (?:
579 [(]
580 (?&PerlOWS)
581 (?: # CAPTURE:sig
582 (?&MxpSignatureList)?
583 )
584 (?&PerlOWS)
585 [)]
586 )?
587 (?&PerlOWS)
588 (?: (?&MxpBlockLike) ) # CAPTURE:code
589 (?&PerlOWS)
590 )#</MxpMethodSyntax>
591
592 (?<MxpSymMethodSyntax>
593
594 (?&PerlOWS)
595 (?: \$? (?&MxpSimpleIdentifier) ) # CAPTURE:name
596 (?&PerlOWS)
597 (?: ( (?&MxpAttribute) (?&PerlOWS) )+ )? # CAPTURE:attributes
598 (?&PerlOWS)
599 (?:
600 [(]
601 (?&PerlOWS)
602 (?: # CAPTURE:sig
603 (?&MxpSignatureList)?
604 )
605 (?&PerlOWS)
606 [)]
607 )?
608 (?&PerlOWS)
609 (?: (?&MxpBlockLike) ) # CAPTURE:code
610 (?&PerlOWS)
611 )#</MxpSymMethodSyntax>
612
613 (?<MxpMultiSyntax>
614
615 (?&PerlOWS)
616 (?: method | factory ) # CAPTURE:kind
617 (?&PerlOWS)
618 (?: \$? (?&MxpSimpleIdentifier) ) # CAPTURE:name
619 (?&PerlOWS)
620 (?: ( (?&MxpAttribute) (?&PerlOWS) )+ )? # CAPTURE:attributes
621 (?&PerlOWS)
622 (?:
623 [(]
624 (?&PerlOWS)
625 (?: # CAPTURE:sig
626 (?&MxpSignatureList)?
627 )
628 (?&PerlOWS)
629 [)]
630 )?
631 (?&PerlOWS)
632 (?: (?&MxpBlockLike) ) # CAPTURE:code
633 (?&PerlOWS)
634 )#</MxpMultiSyntax>
635
636 (?<MxpModifierSyntax>
637
638 (?&PerlOWS)
639 (?: (?&MxpSimpleIdentifiers) ) # CAPTURE:name
640 (?&PerlOWS)
641 (?: ( (?&MxpAttribute) (?&PerlOWS) )+ )? # CAPTURE:attributes
642 (?&PerlOWS)
643 (?:
644 [(]
645 (?&PerlOWS)
646 (?: # CAPTURE:sig
647 (?&MxpSignatureList)?
648 )
649 (?&PerlOWS)
650 [)]
651 )?
652 (?&PerlOWS)
653 (?: (?&MxpBlockLike) ) # CAPTURE:code
654 (?&PerlOWS)
655 )#</MxpModifierSyntax>
656
657 # Easier to provide two separate patterns for `factory`
658
659 (?<MxpFactorySyntax>
660
661 (?&PerlOWS)
662 (?: (?&MxpSimpleIdentifier) ) # CAPTURE:name
663 (?&PerlOWS)
664 (?: ( (?&MxpAttribute) (?&PerlOWS) )+ )? # CAPTURE:attributes
665 (?&PerlOWS)
666 (?:
667 [(]
668 (?&PerlOWS)
669 (?: # CAPTURE:sig
670 (?&MxpSignatureList)?
671 )
672 (?&PerlOWS)
673 [)]
674 )?
675 (?&PerlOWS)
676 (?: (?&MxpBlockLike) ) # CAPTURE:code
677 (?&PerlOWS)
678 )#</MxpFactorySyntax>
679
680 (?<MxpFactoryViaSyntax>
681
682 (?&PerlOWS)
683 (?: (?&MxpSimpleIdentifier) ) # CAPTURE:name
684 (?&PerlOWS)
685 (?:
686 (?: via )
687 (?&PerlOWS)
688 (?: (?&MxpSimpleIdentifier) ) # CAPTURE:via
689 )?
690 (?&PerlOWS)
691 )#</MxpFactoryViaSyntax>
692
693 (?<MxpCoerceSyntax>
694
695 (?&PerlOWS)
696 (?: from )?
697 (?&PerlOWS)
698 (?: # CAPTURE:from
699 (?&MxpExtendedTypeSpec)
700 )
701 (?&PerlOWS)
702 (?: via )
703 (?&PerlOWS)
704 (?: # CAPTURE:via
705 (?&PerlBlock)|(?&PerlIdentifier)|(?&PerlString)
706 )
707 (?&PerlOWS)
708 (?: (?&MxpBlockLike) )? # CAPTURE:code
709 (?&PerlOWS)
710 )#</MxpCoerceSyntax>
711
712 # try/catch/finally is implemented by another module
713 # but we need to be able to grok it to be able to parse
714 # blocks
715 #
716 (?<TrySyntax>
717
718 (?&PerlOWS)
719 (?: do )?
720 (?&PerlOWS)
721 (?&PerlBlock)
722 (?:
723 (?&PerlOWS)
724 catch
725 (?&PerlOWS)
726 (?&PerlBlock)
727 )?
728 (?:
729 (?&PerlOWS)
730 finally
731 (?&PerlOWS)
732 (?&PerlBlock)
733 )?
734 (?&PerlOWS)
735 )#</TrySyntax>
736
737 )
738 $PPR::GRAMMAR
739 }xso;
740  
741 31 my %_fetch_re_cache;
742 sub _fetch_re {
743 268 ▶ my $key = "@_";
Subroutine _fetch_re: called CC=9 SCAR=22.2
744 268 my $name = shift;
745 268 my %opts = @_;
746
747 268 ▶ $opts{anchor} ||= '';
Condition100%2/2
$opts{"anchor"} ||= ""
l!l
22345
MC/DC100%1/1
$opts{"anchor"} ||= ""
$opts{"anchor"}
Truth table100%2/2
A
A= $opts{"anchor"}
Aresult
11
00
748
749 268 ▶ $_fetch_re_cache{$key} ||= do {
Condition66%2/3
$_fetch_re_cache{$key} ||= do {
l!l&&r!l&&!r
1201480
MC/DC0%0/2
$_fetch_re_cache{$key} ||= do { "$Zydeco::GRAMMAR" =~ m[<$name>(.+)</$name>]su or die "could not fetch re for $name"; (my $re = $1) =~ s/\)\#$//u; my @lines = split(/\n/u, $re, 0); foreach $_ (@lines) { if (my($named_capture) = /# CAPTURE:(\w+)/u) { s/\(\?\:/(?<$named_capture>/u; } ; } ; $re = join("\n", @lines); $opts{"anchor"} eq "start" ? qr/ ^ $re $Zydeco::GRAMMAR /sux : ($opts{"anchor"} eq "end" ? qr/ $re $Zydeco::GRAMMAR $ /sux : ($opts{"anchor"} eq "both" ? qr/ ^ $re $Zydeco::GRAMMAR $ /sux : qr/ $re $Zydeco::GRAMMAR /sux)) }
$_fetch_re_cache{$key} do { "$Zydeco::GRAMMAR" =~ m[<$name>(.+)</$name>]su or die "could not fetch re for $name"; (my $re = $1) =~ s/\)\#$//u; my @lines = split(/\n/u, $re, 0); foreach $_ (@lines) { if (my($named_capture) = /# CAPTURE:(\w+)/u) { s/\(\?\:/(?<$named_capture>/u; } ; } ; $re = join("\n", @lines); $opts{"anchor"} eq "start" ? qr/ ^ $re $Zydeco::GRAMMAR /sux : ($opts{"anchor"} eq "end" ? qr/ $re $Zydeco::GRAMMAR $ /sux : ($opts{"anchor"} eq "both" ? qr/ ^ $re $Zydeco::GRAMMAR $ /sux : qr/ $re $Zydeco::GRAMMAR /sux)) }
Truth table66%2/3
A ||= B
A= $_fetch_re_cache{$key}B= do { "$Zydeco::GRAMMAR" =~ m[<$name>(.+)</$name>]su or die "could not fetch re for $name"; (my $re = $1) =~ s/\)\#$//u; my @lines = split(/\n/u, $re, 0); foreach $_ (@lines) { if (my($named_capture) = /# CAPTURE:(\w+)/u) { s/\(\?\:/(?<$named_capture>/u; } ; } ; $re = join("\n", @lines); $opts{"anchor"} eq "start" ? qr/ ^ $re $Zydeco::GRAMMAR /sux : ($opts{"anchor"} eq "end" ? qr/ $re $Zydeco::GRAMMAR $ /sux : ($opts{"anchor"} eq "both" ? qr/ ^ $re $Zydeco::GRAMMAR $ /sux : qr/ $re $Zydeco::GRAMMAR /sux)) }
ABresult
1X1
011
000
750 148 ▶ "$GRAMMAR" =~ m{<$name>(.+)</$name>}s or die "could not fetch re for $name";
Branch: 1 branch
BranchTrueFalseTotal
"$Zydeco::GRAMMAR" =~ m[<$name>(.+)</$name>]su or die "could not fetch re for $name" 0 148 148
751 148 (my $re = $1) =~ s/\)\#$//;
752 148 my @lines = split /\n/, $re;
753 148 for (@lines) {
754 2697 ▶ if (my ($named_capture) = /# CAPTURE:(\w+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($named_capture) = /# CAPTURE:(\w+)/u) 456 2241 2697
755 456 s/\(\?\:/\(\?<$named_capture>/;
756 }
757 }
758 148 $re = join "\n", @lines;
759 $opts{anchor} eq 'start' ? qr/ ^ $re $GRAMMAR /xs :
760 $opts{anchor} eq 'end' ? qr/ $re $GRAMMAR $ /xs :
761 148 ▶ $opts{anchor} eq 'both' ? qr/ ^ $re $GRAMMAR $ /xs : qr/ $re $GRAMMAR /xs
Branch: 3 branches
BranchTrueFalseTotal
$opts{'anchor'} eq 'start' ? : 108 40 148
$opts{'anchor'} eq 'end' ? : 0 40 40
$opts{'anchor'} eq 'both' ? : 0 40 40
762 }
763 }
764  
765 #
766 # HELPERS
767 #
768  
769 sub _handle_signature_list {
770 48 ▶ my $me = shift;
Subroutine _handle_signature_list: called CC=47 SCAR=39.9
771 48 my $sig = $_[0];
772 48 my $seen_named = 0;
773 48 my $seen_pos = 0;
774 48 my @parsed;
775
776 return (
777 48 ▶ 0,
Branch: 1 branch
BranchTrueFalseTotal
unless $sig 6 42 48
778 '',
779 '[]',
780 '',
781 ) if !$sig;
782
783 42 ▶ while ($sig) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sig) 65 42 107
784 65 $sig =~ s/^\s+//xs;
785 65 ▶ last if !$sig;
Branch: 1 branch
BranchTrueFalseTotal
unless $sig 0 65 65
786
787 65 push @parsed, {};
788
789 65 ▶ if ($sig =~ /^((?&PerlBlock)) $GRAMMAR/xso) {
Branch: 2 branches
BranchTrueFalseTotal
if ($sig =~ /^((?&PerlBlock)) $Zydeco::GRAMMAR/osux) { } 5 60 65
elsif ($sig =~ /^((?&MxpTypeSpec)) $Zydeco::GRAMMAR/osux) { } 51 9 60
790 5 my $type = $1;
791 5 $parsed[-1]{type} = $type;
792 5 $parsed[-1]{type_is_block} = 1;
793 5 $sig =~ s/^\Q$type//xs;
794 5 $sig =~ s/^((?&PerlOWS)) $GRAMMAR//xso;
795 }
796 elsif ($sig =~ /^((?&MxpTypeSpec)) $GRAMMAR/xso) {
797 51 my $type = $1;
798 51 ▶ $parsed[-1]{type} = ($type =~ /#/) ? $type->$decomment : $type;
Branch: 1 branch
BranchTrueFalseTotal
$type =~ /#/u ? : 1 50 51
799 51 $parsed[-1]{type_is_block} = 0;
800 51 $sig =~ s/^\Q$type//xs;
801 51 $sig =~ s/^((?&PerlOWS)) $GRAMMAR//xso;
802 }
803 else {
804 9 $parsed[-1]{type} = 'Any';
805 9 $parsed[-1]{type_is_block} = 0;
806 }
807
808 65 ▶ if ($sig =~ /^\*((?&PerlIdentifier)) $GRAMMAR/xso) {
Branch: 3 branches
BranchTrueFalseTotal
if ($sig =~ /^\*((?&PerlIdentifier)) $Zydeco::GRAMMAR/osux) { } 14 51 65
elsif ($sig =~ /^ ( [\$\@\%] ) (?: [=),?] | (?&PerlNWS) | $ ) $Zydeco::GRAMMAR/osux) { } 1 50 51
elsif ($sig =~ /^((?&MxpSignatureVariable)) $Zydeco::GRAMMAR/osux) { } 50 0 50
809 14 my $name = $1;
810 14 $parsed[-1]{name} = $name;
811 14 $parsed[-1]{named} = 1;
812 14 $parsed[-1]{positional} = 0;
813 14 ++$seen_named;
814 14 $sig =~ s/^\*\Q$name//xs;
815 14 $sig =~ s/^((?&PerlOWS)) $GRAMMAR//xso;
816 }
817 elsif ($sig =~ /^ ( [\$\@\%] ) (?: [=),?] | (?&PerlNWS) | $ ) $GRAMMAR/xso) {
818 1 state $dummy = 0;
819 1 my $name = substr($sig,0,1) . '____ZYDECO_DUMMY_VAR_' . ++$dummy;
820 1 $parsed[-1]{name} = $name;
821 1 $parsed[-1]{named} = 0;
822 1 $parsed[-1]{positional} = 1;
823 1 $sig = substr($sig, 1);
824 1 $sig =~ s/^((?&PerlOWS)) $GRAMMAR//xs;
825 }
826 elsif ($sig =~ /^((?&MxpSignatureVariable)) $GRAMMAR/xso) {
827 50 my $name = $1;
828 50 $parsed[-1]{name} = $name;
829 50 $parsed[-1]{named} = 0;
830 50 $parsed[-1]{positional} = 1;
831 50 ++$seen_pos;
832 50 $sig =~ s/^\Q$name//xs;
833 50 $sig =~ s/^((?&PerlOWS)) $GRAMMAR//xs;
834 }
835
836 65 ▶ if ($sig =~ /^\?/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($sig =~ /^\?/u) { } 5 60 65
elsif ($sig =~ /^=((?&PerlOWS))((?&PerlScalarExpression)) $Zydeco::GRAMMAR/osux) { } 2 58 60
837 5 $parsed[-1]{optional} = 1;
838 5 $sig =~ s/^\?((?&PerlOWS)) $GRAMMAR//xso;
839 }
840 elsif ($sig =~ /^=((?&PerlOWS))((?&PerlScalarExpression)) $GRAMMAR/xso) {
841 2 my ($ws, $default) = ($1, $2);
842 2 $parsed[-1]{default} = $default;
843
844 2 $sig =~ s/^=\Q$ws$default//xs;
845 2 $sig =~ s/^((?&PerlOWS)) $GRAMMAR//xso;
846
847 2 ▶ if ($default =~ / \$ (?: class|self) /xso) {
Branch: 1 branch
BranchTrueFalseTotal
if ($default =~ / \$ (?: class|self) /osux) 0 2 2
848 0 require PadWalker;
849 0 $default = sprintf('do { my $invocants = PadWalker::peek_my(2)->{q[@invocants]}||PadWalker::peek_my(1)->{q[@invocants]}; my $self=$invocants->[-1]; my $class=ref($self)||$self; %s }', $default);
850 0 $parsed[-1]{default} = $default;
851 }
852 }
853
854 65 ▶ if ($sig) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sig) 23 42 65
855 23 ▶ if ($sig =~ /^,/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sig =~ /^,/u) { } 23 0 23
856 23 $sig =~ s/^,//;
857 }
858 else {
859 0 require Carp;
860 0 Carp::croak(sprintf "Could not parse signature (%s), remaining: %s", $_[0], $sig);
861 }
862 }
863 }
864
865 42 my @signature_var_list;
866 42 my $type_params_stuff = '[';
867
868 42 my (@head, @tail);
869 42 ▶ if ($seen_named and $seen_pos) {
Branch: 1 branch
BranchTrueFalseTotal
if ($seen_named and $seen_pos) 2 40 42
Condition100%3/3
$seen_named and $seen_pos
!ll&&!rl&&r
3552
MC/DC100%2/2
$seen_named and $seen_pos
$seen_named $seen_pos
Truth table100%3/3
A and B
A= $seen_namedB= $seen_pos
ABresult
0X0
100
111
870 2 ▶ while (@parsed and $parsed[0]{positional}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@parsed and $parsed[0]{"positional"}) 4 2 6
Condition66%2/3
@parsed and $parsed[0]{"positional"}
!ll&&!rl&&r
024
MC/DC50%1/2
@parsed and $parsed[0]{"positional"}
@parsed $parsed[0]{"positional"}
Truth table66%2/3
A and B
A= @parsedB= $parsed[0]{"positional"}
ABresult
0X0
100
111
871 4 push @head, shift @parsed;
872 }
873 2 ▶ while (@parsed and $parsed[-1]{positional}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@parsed and $parsed[-1]{"positional"}) 2 2 4
Condition66%2/3
@parsed and $parsed[-1]{"positional"}
!ll&&!rl&&r
022
MC/DC50%1/2
@parsed and $parsed[-1]{"positional"}
@parsed $parsed[-1]{"positional"}
Truth table66%2/3
A and B
A= @parsedB= $parsed[-1]{"positional"}
ABresult
0X0
100
111
874 2 unshift @tail, pop @parsed;
875 }
876 2 ▶ if (grep $_->{positional}, @parsed) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep $_->{"positional"}, @parsed) 0 2 2
877 0 require Carp;
878 0 Carp::croak("Signature contains an unexpected mixture of positional and named parameters");
879 }
880 2 for my $p (@head, @tail) {
881 6 my $is_optional = $p->{optional};
882 6 ▶ $is_optional ||= ($p->{type} =~ /^Optional/s);
Condition33%1/3
$is_optional ||= $p->{"type"} =~ /^Optional/su
l!l&&r!l&&!r
006
MC/DC0%0/2
$is_optional ||= $p->{"type"} =~ /^Optional/su
$is_optional $p->{"type"} =~ /^Optional/su
Truth table33%1/3
A ||= B
A= $is_optionalB= $p->{"type"} =~ /^Optional/su
ABresult
1X1
011
000
883 6 ▶ if ($is_optional) {
Branch: 3 branches
BranchTrueFalseTotal
if ($is_optional) { } 0 6 6
elsif ($p->{'default'}) { } 0 6 6
elsif ($p->{'name'} =~ /^[\@\%]/u) { } 0 6 6
884 0 require Carp;
885 0 Carp::croak("Cannot have optional positional parameter $p->{name} in signature with named parameters");
886 }
887 elsif ($p->{default}) {
888 0 require Carp;
889 0 Carp::croak("Cannot have positional parameter $p->{name} with default in signature with named parameters");
890 }
891 elsif ($p->{name} =~ /^[\@\%]/) {
892 0 require Carp;
893 0 Carp::croak("Cannot have slurpy parameter $p->{name} in signature with named parameters");
894 }
895 }
896 }
897
898 42 require B;
899  
900 42 my $extra = '';
901 42 my $count = @parsed;
902 42 ▶ while (my $p = shift @parsed) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $p = shift @parsed) 59 42 101
903 59 ▶ $type_params_stuff .= B::perlstring($p->{name}) . ',' if $seen_named;
Branch: 1 branch
BranchTrueFalseTotal
if $seen_named 14 45 59
904 59 ▶ if ($p->{name} =~ /^[\@\%]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p->{'name'} =~ /^[\@\%]/u) { } 3 56 59
905 3 ▶ if (@parsed) {
Branch: 1 branch
BranchTrueFalseTotal
if (@parsed) 0 3 3
906 0 require Carp;
907 0 Carp::croak("Cannot have slurpy parameter $p->{name} in non-final position");
908 }
909 $extra .= sprintf(
910 'my (%s) = (@_==%d ? %s{$_[-1]} : ());',
911 $p->{name},
912 $count,
913 3 substr($p->{name}, 0, 1),
914 );
915 3 $p->{slurpy} = 1;
916 3 ▶ if ($p->{type} eq 'Any') {
Branch: 1 branch
BranchTrueFalseTotal
if ($p->{"type"} eq "Any") 2 1 3
917 2 ▶ $p->{type} = substr($p->{name}, 0, 1) eq '%' ? 'HashRef' : 'ArrayRef';
Branch: 1 branch
BranchTrueFalseTotal
substr($p->{'name'}, 0, 1) eq '%' ? : 1 1 2
918 }
919 }
920 else {
921 56 push @signature_var_list, $p->{name};
922 }
923
924 59 ▶ if ($p->{type_is_block}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p->{'type_is_block'}) { } 3 56 59
925 3 $type_params_stuff .= sprintf('scalar(do %s)', $p->{type}) . ',';
926 }
927 else {
928 56 $type_params_stuff .= B::perlstring($p->{type}) . ',';
929 }
930 59 ▶ if (exists $p->{optional} or exists $p->{default} or $p->{slurpy}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $p->{"optional"} or exists $p->{"default"} or $p->{"slurpy"}) 5 49 54
Condition100%6/6
exists $p->{"optional"} or exists $p->{"default"} or $p->{"slurpy"}
l!l&&r!l&&!r
7349
exists $p->{"optional"} or exists $p->{"default"}
l!l&&r!l&&!r
5252
MC/DC100%3/3
exists $p->{"optional"} or exists $p->{"default"} or $p->{"slurpy"}
exists $p->{"optional"} exists $p->{"default"} $p->{"slurpy"}
Truth table100%4/4
A or B or C
A= exists $p->{"optional"}B= exists $p->{"default"}C= $p->{"slurpy"}
ABCresult
1XX1
01X1
0011
0000
931 10 $type_params_stuff .= '{';
932 10 ▶ $type_params_stuff .= sprintf('optional=>%d,', !!$p->{optional}) if exists $p->{optional};
Branch: 1 branch
BranchTrueFalseTotal
if exists $p->{"optional"} 5 5 10
933 10 ▶ $type_params_stuff .= sprintf('default=>sub{scalar(%s)},', $p->{default}) if exists $p->{default};
Branch: 1 branch
BranchTrueFalseTotal
if exists $p->{"default"} 2 8 10
934 10 ▶ $type_params_stuff .= sprintf('slurpy=>%d,', !!$p->{slurpy}) if exists $p->{slurpy};
Branch: 1 branch
BranchTrueFalseTotal
if exists $p->{"slurpy"} 3 7 10
935 10 $type_params_stuff .= '},';
936 }
937 }
938
939 42 ▶ @signature_var_list = '$arg' if $seen_named;
Branch: 1 branch
BranchTrueFalseTotal
if $seen_named 7 35 42
940 42 $type_params_stuff .= ']';
941
942 42 ▶ if (@head or @tail) {
Branch: 1 branch
BranchTrueFalseTotal
if (@head or @tail) 2 40 42
Condition66%2/3
@head or @tail
l!l&&r!l&&!r
2040
MC/DC50%1/2
@head or @tail
@head @tail
Truth table66%2/3
A or B
A= @headB= @tail
ABresult
1X1
011
000
943 2 require Type::Params;
944 2 'Type::Params'->VERSION(1.009002);
945 2 ▶ my $head_stuff = join(q[,] => map { $_->{type_is_block} ? sprintf('scalar(do %s)', $_->{type}) : B::perlstring($_->{type}) } @head);
Branch: 1 branch
BranchTrueFalseTotal
$_->{'type_is_block'} ? : 2 2 4
946 2 ▶ my $tail_stuff = join(q[,] => map { $_->{type_is_block} ? sprintf('scalar(do %s)', $_->{type}) : B::perlstring($_->{type}) } @tail);
Branch: 1 branch
BranchTrueFalseTotal
$_->{'type_is_block'} ? : 0 2 2
947 2 ▶ my $opts = sprintf('{head=>%s,tail=>%s},', $head_stuff?"[$head_stuff]":0, $tail_stuff?"[$tail_stuff]":0);
Branch: 2 branches
BranchTrueFalseTotal
$head_stuff ? : 2 0 2
$tail_stuff ? : 2 0 2
948 2 substr($type_params_stuff, 1, 0) = $opts; # insert options after "["
949 2 unshift @signature_var_list, map $_->{name}, @head;
950 2 push @signature_var_list, map $_->{name}, @tail;
951 }
952
953 return (
954 42 $seen_named,
955 join(',', @signature_var_list),
956 $type_params_stuff,
957 $extra,
958 );
959 }
960  
961 sub _handle_role_list {
962 31 ▶ my $me = shift;
Subroutine _handle_role_list: called CC=11 SCAR=24.3
963 31 my ($rolelist, $kind) = @_;
964 31 my @return;
965
966 31 ▶ while (length $rolelist) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $rolelist) 37 31 68
967 37 $rolelist =~ s/^\s+//xs;
968
969 37 my $prefix = '';
970 37 my $role = undef;
971 37 my $role_is_block = 0;
972 37 my $suffix = '';
973 37 my $role_params = undef;
974
975 37 ▶ if ($rolelist =~ /^((?&PerlBlock)) $GRAMMAR/xso) {
Branch: 2 branches
BranchTrueFalseTotal
if ($rolelist =~ /^((?&PerlBlock)) $Zydeco::GRAMMAR/osux) { } 3 34 37
elsif ($rolelist =~ /^((?&PerlQualifiedIdentifier)) $Zydeco::GRAMMAR/osux) { } 34 0 34
976 3 $role = $1;
977 3 $role_is_block = 1;
978 3 $rolelist =~ s/^\Q$role//xs;
979 3 $rolelist =~ s/^\s+//xs;
980 }
981 elsif ($rolelist =~ /^((?&PerlQualifiedIdentifier)) $GRAMMAR/xso) {
982 34 $role = $1;
983 34 $rolelist =~ s/^\Q$role//xs;
984 34 $rolelist =~ s/^\s+//xs;
985 }
986 else {
987 0 require Carp;
988 0 Carp::croak("Expected role name, got $rolelist");
989 }
990
991 37 ▶ if ($rolelist =~ /^\?/xs) {
Branch: 2 branches
BranchTrueFalseTotal
if ($rolelist =~ /^\?/sux) { } 8 29 37
elsif ($rolelist =~ /^((?&PerlOWS)(?&PerlList)(?&PerlOWS)) $Zydeco::GRAMMAR/osux) { } 6 23 29
992 8 ▶ if ($kind eq 'class') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "class") 0 8 8
993 0 require Carp;
994 0 Carp::croak("Unexpected question mark suffix in class list");
995 }
996 8 $suffix = '?';
997 8 $rolelist =~ s/^\?\s*//xs;
998 }
999 elsif ($rolelist =~ /^((?&PerlOWS)(?&PerlList)(?&PerlOWS)) $GRAMMAR/xso) {
1000 6 $role_params = $1;
1001 6 $rolelist =~ s/^\Q$role_params//xs;
1002 6 $rolelist =~ s/^\s+//xs;
1003 }
1004
1005 37 ▶ if ($role_is_block) {
Branch: 1 branch
BranchTrueFalseTotal
if ($role_is_block) { } 3 34 37
1006 3 push @return, sprintf('sprintf(q(%s%%s%s), scalar(do %s))', $prefix, $suffix, $role);
1007 }
1008 else {
1009 34 push @return, B::perlstring("$prefix$role$suffix");
1010 }
1011 37 ▶ if ($role_params) {
Branch: 1 branch
BranchTrueFalseTotal
if ($role_params) 6 31 37
1012 6 push @return, sprintf('[%s]', $role_params);
1013 }
1014
1015 37 $rolelist =~ s/^\s+//xs;
1016 37 ▶ if (length $rolelist) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $rolelist) 6 31 37
1017 6 ▶ if ($rolelist =~ /^,/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rolelist =~ /^,/u) { } 6 0 6
1018 6 $rolelist =~ s/^\,\s*//;
1019 }
1020 else {
1021 0 require Carp;
1022 0 Carp::croak(sprintf "Could not parse role list (%s), remaining: %s", $_[0], $rolelist);
1023 }
1024 }
1025 }
1026
1027 31 return join(",", @return);
1028 }
1029  
1030 sub _stringify_attributes {
1031 53 ▶ my @quoted = map sprintf(q("%s"), quotemeta(substr $_, 1)), @{ $_[1] || [] };
Subroutine _stringify_attributes: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
$_[1] or [] 0 53 53
1032 53 sprintf '[%s]', join q[,], @quoted;
1033 }
1034  
1035 sub _handle_name_list {
1036 36 ▶ my ($me, $names) = @_;
Subroutine _handle_name_list: called CC=2 SCAR=7.0
1037 36 ▶ return unless $names;
Branch: 1 branch
BranchTrueFalseTotal
unless $names 0 36 36
1038
1039 36 state $re = _fetch_re('MxpDecoratedIdentifierSolo');
1040 36 my @names = grep defined, ($names =~ /($re) $GRAMMAR/xg);
1041 36 return @names;
1042 }
1043  
1044 my $_should_optimize = sub {
1045 7 ▶ my ($code, $sigvars) = @_;
Subroutine __ANON__: called CC=5 SCAR=16.3
1046
1047 7 my %allowed = ( '$self' => undef, '$class' => undef, '$_' => undef, '@_' => undef );
1048 7 ▶ undef $allowed{$_} for split /\s*,\s*/, $sigvars//'';
Condition100%2/2
$sigvars // ""
l!l
61
MC/DC100%1/1
$sigvars // ""
$sigvars
Truth table100%2/2
A
A= $sigvars
Aresult
11
00
1049
1050 7 my @vars = ( $code =~ /[\$\@\%]\w+/g );
1051 7 foreach my $var (@vars) {
1052 7 ▶ next if exists $allowed{$var};
Branch: 1 branch
BranchTrueFalseTotal
if exists $allowed{$var} 7 0 7
1053 0 return 0;
1054 }
1055 7 1;
1056 31 };
1057  
1058 31 my $DCTX = sprintf( 'definition_context => { file => __FILE__, line => __LINE__, package => __PACKAGE__, via => q(%s) }', __PACKAGE__ );
1059  
1060 sub _handle_factory_keyword {
1061 3 ▶ my ($me, $name, $via, $code, $has_sig, $sig, $attrs) = @_;
Subroutine _handle_factory_keyword: called CC=15 SCAR=37.2
1062
1063 3 ▶ my ($signature_is_named, $signature_var_list, $type_params_stuff, $extra) = $has_sig ? $me->_handle_signature_list($sig) : ();
Branch: 1 branch
BranchTrueFalseTotal
$has_sig ? : 2 1 3
1064
1065 3 my $optim;
1066 3 for my $attr (@$attrs) {
1067 0 ▶ $optim = 1 if $attr =~ /^:optimize\b/;
Branch: 1 branch
BranchTrueFalseTotal
if $attr =~ /^:optimize\b/u 0 0 0
1068 }
1069
1070 3 ▶ if (defined $code and $code =~ /^=(.+)$/s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $code and $code =~ /^=(.+)$/su) 0 3 3
Condition66%2/3
defined $code and $code =~ /^=(.+)$/su
!ll&&!rl&&r
120
MC/DC0%0/2
defined $code and $code =~ /^=(.+)$/su
defined $code $code =~ /^=(.+)$/su
Truth table66%2/3
A and B
A= defined $codeB= $code =~ /^=(.+)$/su
ABresult
0X0
100
111
1071 0 $code = "{ $1 }";
1072 0 ▶ $optim ||= $_should_optimize->($code, $signature_var_list);
Condition0%0/3
$optim ||= &$_should_optimize($code, $signature_var_list)
l!l&&r!l&&!r
000
MC/DC0%0/2
$optim ||= &$_should_optimize($code, $signature_var_list)
$optim &$_should_optimize($code, $signature_var_list)
Truth table0%0/3
A ||= B
A= $optimB= &$_should_optimize($code, $signature_var_list)
ABresult
1X1
011
000
1073 }
1074
1075 3 ▶ if ($via) {
Branch: 1 branch
BranchTrueFalseTotal
if ($via) 1 2 3
1076 1 ▶ return sprintf(
Branch: 2 branches
BranchTrueFalseTotal
$name =~ /^\{/u ? : 0 1 1
$via =~ /^\{/u ? : 0 1 1
1077 'q[%s]->_factory(%s, \\(%s));',
1078 $me,
1079 ($name =~ /^\{/ ? "scalar(do $name)" : B::perlstring($name)),
1080 ($via =~ /^\{/ ? "scalar(do $via)" : B::perlstring($via)),
1081 );
1082 }
1083 2 ▶ if (!$has_sig) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($has_sig) 0 2 2
1084 0 my $munged_code = sprintf('sub { my ($factory, $class) = (@_); do %s }', $code);
1085 0 ▶ return sprintf(
Branch: 2 branches
BranchTrueFalseTotal
$name =~ /^\{/u ? : 0 0 0
$optim ? : 0 0 0
1086 'q[%s]->_factory(%s, { %s, attributes => %s, caller => __PACKAGE__, code => %s, optimize => %d });',
1087 $me,
1088 ($name =~ /^\{/ ? "scalar(do $name)" : B::perlstring($name)),
1089 $DCTX,
1090 $me->_stringify_attributes($attrs),
1091 $optim ? B::perlstring($munged_code) : $munged_code,
1092 !!$optim,
1093 );
1094 }
1095 2 my $munged_code = sprintf('sub { my($factory,$class,%s)=(shift,shift,@_); %s; do %s }', $signature_var_list, $extra, $code);
1096 2 ▶ sprintf(
Branch: 2 branches
BranchTrueFalseTotal
$name =~ /^\{/u ? : 0 2 2
$optim ? : 0 2 2
1097 'q[%s]->_factory(%s, { %s, attributes => %s, caller => __PACKAGE__, code => %s, named => %d, signature => %s, optimize => %d });',
1098 $me,
1099 ($name =~ /^\{/ ? "scalar(do $name)" : B::perlstring($name)),
1100 $DCTX,
1101 $me->_stringify_attributes($attrs),
1102 $optim ? B::perlstring($munged_code) : $munged_code,
1103 !!$signature_is_named,
1104 $type_params_stuff,
1105 !!$optim,
1106 );
1107 }
1108  
1109 sub _handle_method_keyword {
1110 32 ▶ my $me = shift;
Subroutine _handle_method_keyword: called CC=23 SCAR=33.3
1111 32 my ($kind, $name, $code, $has_sig, $sig, $attrs) = @_;
1112
1113 32 ▶ my ($signature_is_named, $signature_var_list, $type_params_stuff, $extra) = $has_sig ? $me->_handle_signature_list($sig) : ();
Branch: 1 branch
BranchTrueFalseTotal
$has_sig ? : 19 13 32
1114
1115 32 my $optim;
1116 32 for my $attr (@$attrs) {
1117 4 ▶ $optim = 1 if $attr =~ /^:optimize\b/;
Branch: 1 branch
BranchTrueFalseTotal
if $attr =~ /^:optimize\b/u 3 1 4
1118 }
1119
1120 32 ▶ if (defined $code and $code =~ /^=(.+)$/s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $code and $code =~ /^=(.+)$/su) 0 32 32
Condition33%1/3
defined $code and $code =~ /^=(.+)$/su
!ll&&!rl&&r
0320
MC/DC0%0/2
defined $code and $code =~ /^=(.+)$/su
defined $code $code =~ /^=(.+)$/su
Truth table33%1/3
A and B
A= defined $codeB= $code =~ /^=(.+)$/su
ABresult
0X0
100
111
1121 0 $code = "{ $1 }";
1122 0 ▶ $optim ||= $_should_optimize->($code, $signature_var_list);
Condition0%0/3
$optim ||= &$_should_optimize($code, $signature_var_list)
l!l&&r!l&&!r
000
MC/DC0%0/2
$optim ||= &$_should_optimize($code, $signature_var_list)
$optim &$_should_optimize($code, $signature_var_list)
Truth table0%0/3
A ||= B
A= $optimB= &$_should_optimize($code, $signature_var_list)
ABresult
1X1
011
000
1123 }
1124
1125 32 my $lex_name;
1126 32 ▶ if (defined $name and $name =~ /^\$(.+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name and $name =~ /^\$(.+)$/u) 1 31 32
Condition100%3/3
defined $name and $name =~ /^\$(.+)$/u
!ll&&!rl&&r
1301
MC/DC100%2/2
defined $name and $name =~ /^\$(.+)$/u
defined $name $name =~ /^\$(.+)$/u
Truth table100%3/3
A and B
A= defined $nameB= $name =~ /^\$(.+)$/u
ABresult
0X0
100
111
1127 1 $lex_name = $name;
1128 }
1129
1130 32 my $inject_vars = 'my $class = ref($self)||$self';
1131 32 ▶ if ( $code =~ /\$\s*factory/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code =~ /\$\s*factory/u) 1 31 32
1132 1 $inject_vars .= '; my $factory = $self->FACTORY';
1133 }
1134
1135 32 my $handler = '_can';
1136 32 ▶ if ( $kind eq 'symmethod' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "symmethod") 7 25 32
1137 7 $handler = '_symmethod';
1138 }
1139
1140 32 my $return = '';
1141
1142 32 ▶ if (defined $name and not defined $lex_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name and not defined $lex_name) { } 30 2 32
Condition100%3/3
defined $name and not defined $lex_name
!ll&&!rl&&r
1130
MC/DC100%2/2
defined $name and not defined $lex_name
defined $name not defined $lex_name
Truth table100%3/3
A and not(B)
A= defined $nameB= not defined $lex_name
ABresult
0X0
100
111
1143 30 ▶ if ($has_sig) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_sig) { } 17 13 30
1144 17 my $munged_code = sprintf('sub { my($self,%s)=(shift,@_); %s; %s; do %s }', $signature_var_list, $extra, $inject_vars, $code);
1145 17 ▶ $return = sprintf(
Branch: 2 branches
BranchTrueFalseTotal
$name =~ /^\{/u ? : 0 17 17
$optim ? : 2 15 17
1146 'q[%s]->%s(%s, { %s, attributes => %s, caller => __PACKAGE__, code => %s, named => %d, signature => %s, optimize => %d });',
1147 $me,
1148 $handler,
1149 ($name =~ /^\{/ ? "scalar(do $name)" : B::perlstring($name)),
1150 $DCTX,
1151 $me->_stringify_attributes($attrs),
1152 $optim ? B::perlstring($munged_code) : $munged_code,
1153 !!$signature_is_named,
1154 $type_params_stuff,
1155 !!$optim,
1156 );
1157 }
1158 else {
1159 13 my $munged_code = sprintf('sub { my $self = $_[0]; %s; do %s }', $inject_vars, $code);
1160 13 ▶ $return = sprintf(
Branch: 2 branches
BranchTrueFalseTotal
$name =~ /^\{/u ? : 0 13 13
$optim ? : 0 13 13
1161 'q[%s]->%s(%s, { %s, attributes => %s, caller => __PACKAGE__, code => %s, optimize => %d });',
1162 $me,
1163 $handler,
1164 ($name =~ /^\{/ ? "scalar(do $name)" : B::perlstring($name)),
1165 $DCTX,
1166 $me->_stringify_attributes($attrs),
1167 $optim ? B::perlstring($munged_code) : $munged_code,
1168 !!$optim,
1169 );
1170 }
1171 }
1172 else {
1173 2 ▶ die if $kind eq 'symmethod';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "symmethod" 0 2 2
1174
1175 2 ▶ if ($has_sig) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_sig) { } 2 0 2
1176 2 my $munged_code = sprintf('sub { my($self,%s)=(shift,@_); %s; %s; do %s }', $signature_var_list, $extra, $inject_vars, $code);
1177 2 ▶ $return = sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$optim ? : 1 1 2
1178 'q[%s]->wrap_coderef({ %s, attributes => %s, caller => __PACKAGE__, code => %s, named => %d, signature => %s, optimize => %d });',
1179 'MooX::Press',
1180 $DCTX,
1181 $me->_stringify_attributes($attrs),
1182 $optim ? B::perlstring($munged_code) : $munged_code,
1183 !!$signature_is_named,
1184 $type_params_stuff,
1185 !!$optim,
1186 );
1187 }
1188 else {
1189 0 my $munged_code = sprintf('sub { my $self = $_[0]; %s; do %s }', $inject_vars, $code);
1190 0 ▶ $return = sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$optim ? : 0 0 0
1191 'q[%s]->wrap_coderef({ %s, attributes => %s, caller => __PACKAGE__, code => %s, optimize => %d });',
1192 'MooX::Press',
1193 $DCTX,
1194 $me->_stringify_attributes($attrs),
1195 $optim ? B::perlstring($munged_code) : $munged_code,
1196 !!$optim,
1197 );
1198 }
1199 }
1200
1201 32 ▶ if ($lex_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lex_name) 1 31 32
1202 1 return "my $lex_name = $return; &Internals::SvREADONLY(\\$lex_name, 1);";
1203 }
1204
1205 31 return $return;
1206 }
1207  
1208 sub _handle_multi_keyword {
1209 16 ▶ my $me = shift;
Subroutine _handle_multi_keyword: called CC=14 SCAR=29.1
1210 16 my ($kind, $name, $code, $has_sig, $sig, $attrs) = @_;
1211
1212 16 ▶ if ( $name =~ /^\$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^\$/u) 4 12 16
1213 4 $name = "{ \\$name }";
1214 }
1215
1216 16 ▶ my ($signature_is_named, $signature_var_list, $type_params_stuff, $extra) = $has_sig ? $me->_handle_signature_list($sig) : ();
Branch: 1 branch
BranchTrueFalseTotal
$has_sig ? : 16 0 16
1217
1218 16 my $optim;
1219 16 my $extra_code = '';
1220 16 for my $attr (@$attrs) {
1221 2 ▶ $optim = 1 if $attr =~ /^:optimize\b/;
Branch: 1 branch
BranchTrueFalseTotal
if $attr =~ /^:optimize\b/u 0 2 2
1222 2 ▶ if (my ($alias) = ($attr =~ /^:alias\((.+)\)$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($alias) = $attr =~ /^:alias\((.+)\)$/u) 2 0 2
1223 2 $extra_code .= sprintf('alias=>%s', B::perlstring($alias));
1224 }
1225 }
1226
1227 16 ▶ if (defined $code and $code =~ /^=(.+)$/s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $code and $code =~ /^=(.+)$/su) 6 10 16
Condition66%2/3
defined $code and $code =~ /^=(.+)$/su
!ll&&!rl&&r
0106
MC/DC50%1/2
defined $code and $code =~ /^=(.+)$/su
defined $code $code =~ /^=(.+)$/su
Truth table66%2/3
A and B
A= defined $codeB= $code =~ /^=(.+)$/su
ABresult
0X0
100
111
1228 6 $code = "{ $1 }";
1229 6 ▶ $optim ||= $_should_optimize->($code, $signature_var_list);
Condition33%1/3
$optim ||= &$_should_optimize($code, $signature_var_list)
l!l&&r!l&&!r
060
MC/DC0%0/2
$optim ||= &$_should_optimize($code, $signature_var_list)
$optim &$_should_optimize($code, $signature_var_list)
Truth table33%1/3
A ||= B
A= $optimB= &$_should_optimize($code, $signature_var_list)
ABresult
1X1
011
000
1230 }
1231
1232 16 my $inject_vars = 'my $class = ref($self)||$self';
1233
1234 16 ▶ if ($has_sig) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_sig) { } 16 0 16
1235 16 ▶ my $munged_code = sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'factory' ? : 2 14 16
1236 $kind eq 'factory'
1237 ? 'sub { my($factory,$self,%s)=(shift,shift,@_); %s; %s; do %s }'
1238 : 'sub { my($self,%s)=(shift,@_); %s; %s; do %s }',
1239 $signature_var_list,
1240 $extra,
1241 $inject_vars,
1242 $code,
1243 );
1244 16 ▶ return sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /^\{/u ? : 4 12 16
1245 'q[%s]->_multi(%s => %s, { %s, attributes => %s, caller => __PACKAGE__, code => %s, named => %d, signature => %s, %s });',
1246 $me,
1247 $kind,
1248 ($name =~ /^\{/ ? "scalar(do $name)" : B::perlstring($name)),
1249 $DCTX,
1250 $me->_stringify_attributes($attrs),
1251 $munged_code,
1252 !!$signature_is_named,
1253 $type_params_stuff,
1254 $extra_code,
1255 );
1256 }
1257 else {
1258 0 ▶ my $munged_code = sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'factory' ? : 0 0 0
1259 $kind eq 'factory'
1260 ? 'sub { my $factory = $_[0]; my $self = $_[1]; %s; do %s }'
1261 : 'sub { my $self = $_[0]; %s; do %s }',
1262 $inject_vars,
1263 $code,
1264 );
1265 0 ▶ return sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /^\{/u ? : 0 0 0
1266 'q[%s]->_multi(%s => %s, { %s, attributes => %s, caller => __PACKAGE__, code => %s, named => 0, signature => sub { @_ }, %s });',
1267 $me,
1268 $kind,
1269 ($name =~ /^\{/ ? "scalar(do $name)" : B::perlstring($name)),
1270 $DCTX,
1271 $me->_stringify_attributes($attrs),
1272 $munged_code,
1273 $extra_code,
1274 );
1275 }
1276 }
1277  
1278 sub _handle_modifier_keyword {
1279 3 ▶ my ($me, $kind, $names, $code, $has_sig, $sig, $attrs) = @_;
Subroutine _handle_modifier_keyword: called CC=15 SCAR=34.4
1280
1281 3 ▶ my ($signature_is_named, $signature_var_list, $type_params_stuff, $extra) = $has_sig ? $me->_handle_signature_list($sig) : ();
Branch: 1 branch
BranchTrueFalseTotal
$has_sig ? : 0 3 3
1282
1283 3 my $optim;
1284 3 for my $attr (@$attrs) {
1285 0 ▶ $optim = 1 if $attr =~ /^:optimize\b/;
Branch: 1 branch
BranchTrueFalseTotal
if $attr =~ /^:optimize\b/u 0 0 0
1286 }
1287
1288 3 ▶ if (defined $code and $code =~ /^=(.+)$/s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $code and $code =~ /^=(.+)$/su) 1 2 3
Condition66%2/3
defined $code and $code =~ /^=(.+)$/su
!ll&&!rl&&r
021
MC/DC50%1/2
defined $code and $code =~ /^=(.+)$/su
defined $code $code =~ /^=(.+)$/su
Truth table66%2/3
A and B
A= defined $codeB= $code =~ /^=(.+)$/su
ABresult
0X0
100
111
1289 1 $code = "{ $1 }";
1290 1 ▶ $optim ||= $_should_optimize->($code, $signature_var_list);
Condition33%1/3
$optim ||= &$_should_optimize($code, $signature_var_list)
l!l&&r!l&&!r
010
MC/DC0%0/2
$optim ||= &$_should_optimize($code, $signature_var_list)
$optim &$_should_optimize($code, $signature_var_list)
Truth table33%1/3
A ||= B
A= $optimB= &$_should_optimize($code, $signature_var_list)
ABresult
1X1
011
000
1291 }
1292
1293 3 my $inject_vars = 'my $class = ref($self)||$self';
1294 3 ▶ if ( $code =~ /\$\s*factory/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code =~ /\$\s*factory/u) 0 3 3
1295 0 $inject_vars .= '; my $factory = $self->FACTORY';
1296 }
1297
1298 # MooX::Press cannot handle optimizing method modifiers
1299 3 $optim = 0;
1300
1301 3 my @names = $me->_handle_name_list($names);
1302
1303 my $processed_names =
1304 join q[, ],
1305 3 ▶ map { /^\{/ ? "scalar(do $_)" : B::perlstring($_) } @names;
Branch: 1 branch
BranchTrueFalseTotal
/^\{/u ? : 0 5 5
1306
1307 3 ▶ if ($has_sig) {
Branch: 2 branches
BranchTrueFalseTotal
if ($has_sig) { } 0 3 3
elsif ($kind eq 'around') { } 1 2 3
1308 0 my $munged_code;
1309 0 ▶ if ($kind eq 'around') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq 'around') { } 0 0 0
1310 0 $munged_code = sprintf('sub { my($next,$self,%s)=(shift,shift,@_); %s; %s; do %s }', $signature_var_list, $extra, $inject_vars, $code);
1311 }
1312 else {
1313 0 $munged_code = sprintf('sub { my($self,%s)=(shift,@_); %s; %s; do %s }', $signature_var_list, $extra, $inject_vars, $code);
1314 }
1315 0 ▶ sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$optim ? : 0 0 0
1316 'q[%s]->_modifier(q(%s), %s, { %s, attributes => %s, caller => __PACKAGE__, code => %s, named => %d, signature => %s, optimize => %d });',
1317 $me,
1318 $kind,
1319 $processed_names,
1320 $DCTX,
1321 $me->_stringify_attributes($attrs),
1322 $optim ? B::perlstring($munged_code) : $munged_code,
1323 !!$signature_is_named,
1324 $type_params_stuff,
1325 !!$optim,
1326 );
1327 }
1328 elsif ($kind eq 'around') {
1329 1 my $munged_code = sprintf('sub { my ($next, $self) = @_; %s; do %s }', $inject_vars, $code);
1330 1 ▶ sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$optim ? : 0 1 1
1331 'q[%s]->_modifier(q(%s), %s, { %s, attributes => %s, caller => __PACKAGE__, code => %s, optimize => %d });',
1332 $me,
1333 $kind,
1334 $processed_names,
1335 $DCTX,
1336 $me->_stringify_attributes($attrs),
1337 $optim ? B::perlstring($munged_code) : $munged_code,
1338 !!$optim,
1339 );
1340 }
1341 else {
1342 2 my $munged_code = sprintf('sub { my $self = $_[0]; %s; do %s }', $inject_vars, $code);
1343 2 ▶ sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$optim ? : 0 2 2
1344 'q[%s]->_modifier(q(%s), %s, { %s, attributes => %s, caller => __PACKAGE__, code => %s, optimize => %d });',
1345 $me,
1346 $kind,
1347 $processed_names,
1348 $DCTX,
1349 $me->_stringify_attributes($attrs),
1350 $optim ? B::perlstring($munged_code) : $munged_code,
1351 !!$optim,
1352 );
1353 }
1354 }
1355  
1356 sub _handle_package_keyword {
1357 96 ▶ my ($me, $kind, $name, $version, $compact_extends, $compact_with, $code, $has_sig, $sig, $plus, $opts) = @_;
Subroutine _handle_package_keyword: called CC=16 SCAR=28.2
1358
1359 96 my $compact_code = '';
1360 96 ▶ if ($compact_extends) {
Branch: 1 branch
BranchTrueFalseTotal
if ($compact_extends) 6 90 96
1361 6 $compact_code .= sprintf('q[%s]->_extends(%s);', $me, $me->_handle_role_list($compact_extends, 'class'));
1362 }
1363 96 ▶ if ($compact_with) {
Branch: 1 branch
BranchTrueFalseTotal
if ($compact_with) 6 90 96
1364 6 $compact_code .= sprintf('q[%s]->_with(%s);', $me, $me->_handle_role_list($compact_with, 'role'));
1365 }
1366 96 ▶ if ($version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version) 1 95 96
1367 1 ▶ $compact_code .= sprintf('%s::version(%s);', $me, $version =~ /^[0-9]/ ? B::perlstring($version) : $version);
Branch: 1 branch
BranchTrueFalseTotal
$version =~ /^[0-9]/u ? : 1 0 1
1368 }
1369
1370 96 ▶ if ($kind eq 'abstract') {
Branch: 3 branches
BranchTrueFalseTotal
if ($kind eq 'abstract') { } 1 95 96
elsif ($kind eq 'interface') { } 0 95 95
elsif (length $compact_code) { } 9 86 95
1371 1 $kind = 'class';
1372 1 $code = "{ q[$me]->_abstract(1); $compact_code $code }";
1373 }
1374 elsif ($kind eq 'interface') {
1375 0 $kind = 'role';
1376 0 $code = "{ q[$me]->_interface(1); $compact_code $code }";
1377 }
1378 elsif (length $compact_code) {
1379 9 $code = "{ $compact_code $code }";
1380 }
1381
1382 96 ▶ if ($name and $has_sig) {
Branch: 3 branches
BranchTrueFalseTotal
if ($name and $has_sig) { } 8 88 96
elsif ($has_sig) { } 1 87 88
elsif ($name) { } 83 4 87
Condition100%3/3
$name and $has_sig
!ll&&!rl&&r
5838
MC/DC100%2/2
$name and $has_sig
$name $has_sig
Truth table100%3/3
A and B
A= $nameB= $has_sig
ABresult
0X0
100
111
1383 8 my ($signature_is_named, $signature_var_list, $type_params_stuff, $extra) = $me->_handle_signature_list($sig);
1384 8 my $munged_code = sprintf('sub { q(%s)->_package_callback(sub { my ($generator,%s)=(shift,@_); %s; do %s }, @_) }', $me, $signature_var_list, $extra, $code);
1385 8 return sprintf(
1386 'use Zydeco::_Gather -parent => %s; use Zydeco::_Gather -gather, %s => { code => %s, named => %d, signature => %s }; use Zydeco::_Gather -unparent;',
1387 B::perlstring("$plus$name"),
1388 B::perlstring("$kind\_generator:$plus$name"),
1389 $munged_code,
1390 !!$signature_is_named,
1391 $type_params_stuff,
1392 );
1393 }
1394 elsif ($has_sig) {
1395 1 my ($signature_is_named, $signature_var_list, $type_params_stuff, $extra) = $me->_handle_signature_list($sig);
1396 1 my $munged_code = sprintf('sub { q(%s)->_package_callback(sub { my ($generator,%s)=(shift,@_); %s; do %s }, @_) }', $me, $signature_var_list, $extra, $code);
1397 return sprintf(
1398 'q[%s]->anonymous_generator(%s => { code => %s, named => %d, signature => %s }, toolkit => %s, prefix => %s, factory_package => %s, type_library => %s)',
1399 $me,
1400 $kind,
1401 $munged_code,
1402 !!$signature_is_named,
1403 $type_params_stuff,
1404 B::perlstring($opts->{toolkit}||'Moo'),
1405 B::perlstring($opts->{prefix}),
1406 B::perlstring($opts->{factory_package}),
1407 1 ▶ B::perlstring($opts->{type_library}),
Condition50%1/2
$opts->{'toolkit'} || 'Moo'
l!l
10
MC/DC0%0/1
$opts->{'toolkit'} || 'Moo'
$opts->{'toolkit'}
Truth table50%1/2
A
A= $opts->{'toolkit'}
Aresult
11
00
1408 );
1409 }
1410 elsif ($name) {
1411 83 ▶ return $code
Branch: 1 branch
BranchTrueFalseTotal
$code ? : 83 0 83
1412 ? sprintf(
1413 'use Zydeco::_Gather -parent => %s; use Zydeco::_Gather -gather, %s => q[%s]->_package_callback(%s, sub %s); use Zydeco::_Gather -unparent;',
1414 B::perlstring("$plus$name"),
1415 B::perlstring("$kind:$plus$name"),
1416 $me,
1417 $DCTX,
1418 $code,
1419 )
1420 : sprintf(
1421 'use Zydeco::_Gather -gather, %s => {};',
1422 B::perlstring("$kind:$plus$name"),
1423 );
1424 }
1425 else {
1426 4 ▶ $code ||= '{}';
Condition50%1/2
$code ||= "{}"
l!l
40
MC/DC0%0/1
$code ||= "{}"
$code
Truth table50%1/2
A
A= $code
Aresult
11
00
1427 return sprintf(
1428 'q[%s]->anonymous_package(%s => sub { do %s }, toolkit => %s, prefix => %s, factory_package => %s, type_library => %s, %s)',
1429 $me,
1430 $kind,
1431 $code,
1432 B::perlstring($opts->{toolkit}||'Moo'),
1433 B::perlstring($opts->{prefix}),
1434 B::perlstring($opts->{factory_package}),
1435 4 ▶ B::perlstring($opts->{type_library}),
Condition50%1/2
$opts->{'toolkit'} || 'Moo'
l!l
40
MC/DC0%0/1
$opts->{'toolkit'} || 'Moo'
$opts->{'toolkit'}
Truth table50%1/2
A
A= $opts->{'toolkit'}
Aresult
11
00
1436 $DCTX,
1437 );
1438 }
1439 }
1440  
1441 sub _handle_has_keyword {
1442 33 ▶ my ($me, $kw, $names, $rawspec, $default) = @_;
Subroutine _handle_has_keyword: called CC=11 SCAR=25.0
1443
1444 33 ▶ $rawspec = '()' if !defined $rawspec;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rawspec 14 19 33
1445
1446 33 ▶ if (defined $default and $default =~ /\$\s*(?:self|class|factory)/) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $default and $default =~ /\$\s*(?:self|class|factory)/u) { } 0 33 33
elsif (defined $default) { } 6 27 33
Condition66%2/3
defined $default and $default =~ /\$\s*(?:self|class|factory)/u
!ll&&!rl&&r
2760
MC/DC0%0/2
defined $default and $default =~ /\$\s*(?:self|class|factory)/u
defined $default $default =~ /\$\s*(?:self|class|factory)/u
Truth table66%2/3
A and B
A= defined $defaultB= $default =~ /\$\s*(?:self|class|factory)/u
ABresult
0X0
100
111
1447 0 my $inject_vars = 'my $class = ref($self)||$self';
1448 0 ▶ if ( $default =~ /\$\s*factory/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($default =~ /\$\s*factory/u) 0 0 0
1449 0 $inject_vars .= '; my $factory = $self->FACTORY';
1450 }
1451 0 $rawspec = "lazy => !!1, default => sub { my \$self = \$_[0]; $inject_vars; $default }, $rawspec";
1452 }
1453 elsif (defined $default) {
1454 6 $rawspec = "default => sub { $default }, $rawspec";
1455 }
1456
1457 33 $rawspec = "_has_keyword => q[$kw], $rawspec";
1458
1459 33 my @names = $me->_handle_name_list($names);
1460
1461 33 my @r;
1462 my @make_read_only;
1463 33 for my $name (@names) {
1464 37 $name =~ s/^\+\*/+/;
1465 37 $name =~ s/^\*//;
1466
1467 37 ▶ if ($name =~ /^\$(.+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^\$(.+)$/u) { } 1 36 37
1468 1 my $display_name = $1;
1469 1 unshift @r, "my $name";
1470 1 ▶ push @r, sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$display_name =~ /^\{/u ? : 0 1 1
1471 'q[%s]->_has(%s, %s, is => "private", accessor => \\%s, %s)',
1472 $me,
1473 ($display_name =~ /^\{/) ? "scalar(do $display_name)" : B::perlstring($display_name),
1474 $DCTX,
1475 $name,
1476 $rawspec,
1477 );
1478 1 push @make_read_only, $name;
1479 }
1480 else {
1481 36 ▶ push @r, sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /^\{/u ? : 3 33 36
1482 'q[%s]->_has(%s, %s, %s)',
1483 $me,
1484 ($name =~ /^\{/) ? "scalar(do $name)" : B::perlstring($name),
1485 $DCTX,
1486 $rawspec,
1487 );
1488 }
1489 }
1490
1491 33 ▶ if (@make_read_only) {
Branch: 1 branch
BranchTrueFalseTotal
if (@make_read_only) 1 32 33
1492 1 push @r, sprintf(
1493 'q[%s]->_end(sub { &Internals::SvREADONLY($_, 1) for %s; })',
1494 $me,
1495 join(q{,}, map("\\$_", @make_read_only)),
1496 );
1497 }
1498
1499 33 join ";", @r;
1500 }
1501  
1502 sub _handle_requires_keyword {
1503 3 ▶ my ($me, $name, $has_sig, $sig) = @_;
Subroutine _handle_requires_keyword: called CC=4 SCAR=14.0
1504 3 ▶ my $r1 = sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /^\{/u ? : 0 3 3
1505 'q[%s]->_requires(%s);',
1506 $me,
1507 ($name =~ /^\{/ ? "scalar(do $name)" : B::perlstring($name)),
1508 );
1509 3 my $r2 = '';
1510 3 ▶ if (STRICT and $has_sig) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_sig) 2 1 3
1511 2 my ($signature_is_named, $signature_var_list, $type_params_stuff, $extra) = $me->_handle_signature_list($sig);
1512 2 ▶ $r2 = sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /^\{/u ? : 0 2 2
1513 'q[%s]->_modifier(q(around), %s, { caller => __PACKAGE__, code => %s, named => %d, signature => %s, optimize => %d });',
1514 $me,
1515 ($name =~ /^\{/ ? "scalar(do $name)" : B::perlstring($name)),
1516 'sub { my $next = shift; goto $next }',
1517 !!$signature_is_named,
1518 $type_params_stuff,
1519 1,
1520 );
1521 }
1522 3 "$r1$r2";
1523 }
1524  
1525 sub _syntax_error {
1526 0 ▶ require Carp;
Subroutine _syntax_error: not called CC=2 SCAR=17.9
1527 0 ▶ if (ref $_[-1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[-1]) { } 0 0 0
1528 0 my $ref = pop;
1529 0 my ($me, $kind, @poss) = @_;
1530 0 Carp::croak(
1531 "Unexpected syntax in $kind.\n" .
1532 "Expected:\n" .
1533 join("", map "\t$_\n", @poss) .
1534 "Got:\n" .
1535 "\t" . substr($$ref, 0, 32)
1536 );
1537 }
1538 else {
1539 0 my ($me, $kind, $msg) = @_;
1540 0 Carp::croak("Unexpected syntax in $kind.\n" . $msg);
1541 }
1542 }
1543  
1544 31 my $owed = 0;
1545 sub _inject {
1546 222 ▶ my ($me, $ref, $trim_length, $new_code, $pad_at_end) = @_;
Subroutine _inject: called CC=8 SCAR=22.2
1547 222 ▶ $pad_at_end ||= 0;
Condition100%2/2
$pad_at_end ||= 0
l!l
96126
MC/DC100%1/1
$pad_at_end ||= 0
$pad_at_end
Truth table100%2/2
A
A= $pad_at_end
Aresult
11
00
1548
1549 222 my @orig_lines = split /\n/, substr($$ref, 0, $trim_length), -1;
1550 222 my @new_lines = split /\n/, $new_code, -1;
1551
1552 222 ▶ if ($#orig_lines > $#new_lines) {
Branch: 2 branches
BranchTrueFalseTotal
if ($#orig_lines > $#new_lines) { } 127 95 222
elsif ($#orig_lines < $#new_lines) { } 1 94 95
1553 127 my $diff = $#orig_lines - $#new_lines;
1554 127 ▶ if ($owed and $owed > $diff) {
Branch: 2 branches
BranchTrueFalseTotal
if ($owed and $owed > $diff) { } 0 127 127
elsif ($owed) { } 0 127 127
Condition33%1/3
$owed and $owed > $diff
!ll&&!rl&&r
12700
MC/DC0%0/2
$owed and $owed > $diff
$owed $owed > $diff
Truth table33%1/3
A and B
A= $owedB= $owed > $diff
ABresult
0X0
100
111
1555 0 $owed -= $diff;
1556 0 $diff = 0;
1557 }
1558 elsif ($owed) {
1559 0 $diff -= $owed;
1560 0 $owed = 0;
1561 }
1562 127 my $prefix = "\n" x $diff;
1563 127 ▶ $new_code = $pad_at_end ? $new_code.$prefix : $prefix.$new_code;
Branch: 1 branch
BranchTrueFalseTotal
$pad_at_end ? : 67 60 127
1564 }
1565 elsif ($#orig_lines < $#new_lines) {
1566 1 $owed += ($#new_lines - $#orig_lines);
1567 }
1568
1569 222 substr $$ref, 0, $trim_length, $new_code;
1570 }
1571  
1572 #
1573 # KEYWORDS/UTILITIES
1574 #
1575  
1576 31 my @EXPORTABLES = qw(
1577 -booleans
1578 -privacy
1579 -util
1580 -types
1581 -is
1582 -assert
1583 -features
1584 try
1585 class abstract role interface
1586 begin end before_apply after_apply
1587 include toolkit extends with requires
1588 has field param
1589 constant method symmethod multi factory before after around
1590 type_name coerce
1591 version authority overload
1592 );
1593  
1594 sub unimport {
1595 0 ▶ Keyword::Simple::undefine($_) for qw<
Subroutine unimport: not called CC=2 SCAR=17.9
1596 class abstract role interface
1597 begin end before_apply after_apply
1598 include toolkit extends with requires
1599 has field param
1600 constant method symmethod multi factory before after around
1601 type_name coerce
1602 version authority overload
1603 >;
1604 0 goto \&Exporter::Tiny::unimport;
1605 }
1606  
1607 sub _predeclare {
1608 87 ▶ my ($me, $caller, $types, @names) = @_;
Subroutine _predeclare: called CC=3 SCAR=11.9
1609
1610 87 for my $name (@names) {
1611 91 my $cached;
1612 my $T = sub () {
1613 2 ▶ if ( !$cached or $cached->isa('Type::Tiny::_DeclaredType') ) {
Subroutine __ANON__: called CC=6 SCAR=22.1
Branch: 1 branch
BranchTrueFalseTotal
if (not $cached or $cached->isa("Type::Tiny::_DeclaredType")) 2 0 2
Condition33%1/3
not $cached or $cached->isa("Type::Tiny::_DeclaredType")
l!l&&r!l&&!r
200
MC/DC0%0/2
not $cached or $cached->isa("Type::Tiny::_DeclaredType")
not $cached $cached->isa("Type::Tiny::_DeclaredType")
Truth table33%1/3
not(A) or B
A= not $cachedB= $cached->isa("Type::Tiny::_DeclaredType")
ABresult
1X1
011
000
1614 2 ▶ my $got = $types->can('get_type') && $types->get_type($name);
Condition33%1/3
$types->can('get_type') && $types->get_type($name)
!ll&&!rl&&r
002
MC/DC0%0/2
$types->can('get_type') && $types->get_type($name)
$types->can('get_type') $types->get_type($name)
Truth table33%1/3
A && B
A= $types->can('get_type')B= $types->get_type($name)
ABresult
0X0
100
111
1615 2 ▶ $cached = $got if $got;
Branch: 1 branch
BranchTrueFalseTotal
if $got 2 0 2
1616 2 ▶ $cached ||= 'Type::Tiny::_DeclaredType'->new(
Condition33%1/3
$cached ||= "Type::Tiny::_DeclaredType"->new("name", $name, "library", $types)
l!l&&r!l&&!r
200
MC/DC0%0/2
$cached ||= "Type::Tiny::_DeclaredType"->new("name", $name, "library", $types)
$cached "Type::Tiny::_DeclaredType"->new("name", $name, "library", $types)
Truth table33%1/3
A ||= B
A= $cachedB= "Type::Tiny::_DeclaredType"->new("name", $name, "library", $types)
ABresult
1X1
011
000
1617 name => $name,
1618 library => $types,
1619 );
1620 }
1621 2 $cached;
1622 91 };
1623 91 ▶ eval qq{
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
eval "\n\t\t\tpackage Zydeco; # allow namespace::autoclean to clean them\n\t\t\tno warnings 'redefine';\n\t\t\t*${caller}::$name = \$T;\n\t\t\t*${caller}::is_$name = sub (\$) { \$T->()->check(\@_) };\n\t\t\t*${caller}::assert_$name = sub (\$) { \$T->()->assert_return(\@_) };\n\t\t\t1;\n\t\t" or die $@ 0 91 91
1624 package Zydeco; # allow namespace::autoclean to clean them
1625 no warnings 'redefine';
1626 *$caller\::$name = \$T;
1627 *$caller\::is_$name = sub (\$) { \$T->()->check(\@_) };
1628 *$caller\::assert_$name = sub (\$) { \$T->()->assert_return(\@_) };
1629 1;
1630 } or die($@);
1631 }
1632 }
1633  
1634 sub import {
1635 32 ▶ no warnings 'closure';
Subroutine BEGIN: called CC=1 SCAR=0.0
1636 39 ▶ my ($me, %opts) = (shift, @_);
Subroutine import: called CC=36 SCAR=42.1
1637 39 ▶ my $caller = ($opts{caller} ||= caller);
Condition33%1/3
$opts{"caller"} ||= caller
l!l&&r!l&&!r
0390
MC/DC0%0/2
$opts{"caller"} ||= caller
$opts{"caller"} caller
Truth table33%1/3
A ||= B
A= $opts{"caller"}B= caller
ABresult
1X1
011
000
1638
1639 39 ▶ if ('Zydeco::_Gather'->_already($caller)) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Zydeco::_Gather"->_already($caller)) 0 39 39
1640 0 require Carp;
1641 0 Carp::croak("Zydeco is already in scope");
1642 }
1643
1644 39 require MooX::Press;
1645 39 'MooX::Press'->_apply_default_options(\%opts);
1646
1647 39 ▶ my %want = map +($_ => 1), @{ $opts{keywords} || \@EXPORTABLES };
Branch: 1 branch
BranchTrueFalseTotal
$opts{"keywords"} or \@EXPORTABLES 39 0 39
1648
1649 # Optionally export wrapper subs for pre-declared types
1650 #
1651 39 ▶ if ($opts{declare}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"declare"}) 0 39 39
1652 0 my $types = $opts{type_library};
1653 0 $me->_predeclare($caller, $types, @{ $opts{declare} });
1654 }
1655
1656 # Export utility stuff
1657 #
1658 39 Zydeco::_Gather->import::into($caller, -gather => %opts);
1659 39 strict->import::into($caller);
1660 39 warnings->import::into($caller);
1661 MooX::Press::Keywords->import::into($caller, $_)
1662 39 for grep $want{$_}, qw(-booleans -privacy -util);
1663 39 ▶ Syntax::Keyword::Try->import::into($caller) if $want{try};
Branch: 1 branch
BranchTrueFalseTotal
if $want{"try"} 39 0 39
1664 39 ▶ if ($] >= 5.018) {
Branch: 2 branches
BranchTrueFalseTotal
if ($] >= 5.018) { } 39 0 39
elsif ($] >= 5.014) { } 0 0 0
1665 feature->import::into($caller, qw( say state unicode_strings unicode_eval evalbytes current_sub fc ))
1666 39 ▶ if $want{-features};
Branch: 1 branch
BranchTrueFalseTotal
if $want{"-features"} 39 0 39
1667 }
1668 elsif ($] >= 5.014) {
1669 feature->import::into($caller, qw( say state unicode_strings ))
1670 0 ▶ if $want{-features};
Branch: 1 branch
BranchTrueFalseTotal
if $want{"-features"} 0 0 0
1671 }
1672 39 my @libs = qw/ Types::Standard Types::Common::Numeric Types::Common::String /;
1673 39 ▶ push @libs, $opts{type_library} if $opts{type_library}->isa('Type::Library');
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"type_library"}->isa("Type::Library") 1 38 39
1674 39 for my $library (@libs) {
1675 $library->import::into($caller, { replace => 1 }, $_)
1676 118 for grep $want{$_}, qw( -types -is -assert );
1677 }
1678
1679 # `include` keyword
1680 #
1681 Keyword::Simple::define include => sub {
1682 2 ▶ my $ref = shift;
Subroutine __ANON__: called CC=2 SCAR=7.0
1683
1684 2 ▶ $$ref =~ _fetch_re('MxpIncludeSyntax', anchor => 'start') or $me->_syntax_error(
Branch: 1 branch
BranchTrueFalseTotal
$$ref =~ _fetch_re("MxpIncludeSyntax", "anchor", "start") or $me->_syntax_error("include directive", "include <name>", $ref) 0 2 2
1685 'include directive',
1686 'include <name>',
1687 $ref,
1688 );
1689
1690 2 my ($pos, $name) = ($+[0], $+{name});
1691 2 my $qualified = 'MooX::Press'->qualify_name($name, $opts{prefix});
1692 2 $me->_inject($ref, $pos, sprintf('BEGIN { eval(q[%s]->_include(%s)) or die($@) };', $me, B::perlstring($qualified)));
1693 39 ▶ } if $want{include};
Branch: 1 branch
BranchTrueFalseTotal
if $want{"include"} 39 0 39
1694  
1695 # `class` keyword
1696 #
1697 Keyword::Simple::define class => sub {
1698 76 ▶ my $ref = shift;
Subroutine __ANON__: called CC=4 SCAR=13.9
1699
1700 # my $re = _fetch_re('MxpCompactRoleList', anchor => 'start');
1701 # my @r = "Foo with Bar" =~ /($re)/;
1702 # use Data::Dumper;
1703 # die Dumper($r[0], $re);
1704  
1705 76 ▶ $$ref =~ _fetch_re('MxpClassSyntax', anchor => 'start') or $me->_syntax_error(
Branch: 1 branch
BranchTrueFalseTotal
$$ref =~ _fetch_re("MxpClassSyntax", "anchor", "start") or $me->_syntax_error("class declaration", "class <name> (<signature>) { <block> }", "class <name> { <block> }", "class <name>", "class (<signature>) { <block> }", "class { <block> }", "class;", $ref) 0 76 76
1706 'class declaration',
1707 'class <name> (<signature>) { <block> }',
1708 'class <name> { <block> }',
1709 'class <name>',
1710 'class (<signature>) { <block> }',
1711 'class { <block> }',
1712 'class;',
1713 $ref,
1714 );
1715
1716 76 my ($pos, $plus, $name, $version, $sig, $compact_extends, $compact_with, $block) = ($+[0], $+{plus}, $+{name}, $+{version}, $+{sig}, $+{compact_extends}, $+{compact_with}, $+{block});
1717 76 my $has_sig = !!exists $+{sig};
1718 76 ▶ $plus ||= '';
Condition100%2/2
$plus ||= ""
l!l
175
MC/DC100%1/1
$plus ||= ""
$plus
Truth table100%2/2
A
A= $plus
Aresult
11
00
1719 76 ▶ $block ||= '{}';
Condition100%2/2
$block ||= "{}"
l!l
5224
MC/DC100%1/1
$block ||= "{}"
$block
Truth table100%2/2
A
A= $block
Aresult
11
00
1720
1721 76 $me->_inject($ref, $pos, $me->_handle_package_keyword(class => $name, $version, $compact_extends, $compact_with, $block, $has_sig, $sig, $plus, \%opts), 1);
1722 39 ▶ } if $want{class};
Branch: 1 branch
BranchTrueFalseTotal
if $want{"class"} 39 0 39
1723  
1724 Keyword::Simple::define abstract => sub {
1725 1 ▶ my $ref = shift;
Subroutine __ANON__: called CC=4 SCAR=14.3
1726
1727 1 ▶ $$ref =~ _fetch_re('MxpAbstractSyntax', anchor => 'start') or $me->_syntax_error(
Branch: 1 branch
BranchTrueFalseTotal
$$ref =~ _fetch_re("MxpAbstractSyntax", "anchor", "start") or $me->_syntax_error("abstract class declaration", "abstract class <name> (<signature>) { <block> }", "abstract class <name> { <block> }", "abstract class <name>", "abstract class (<signature>) { <block> }", "abstract class { <block> }", "abstract class;", $ref) 0 1 1
1728 'abstract class declaration',
1729 'abstract class <name> (<signature>) { <block> }',
1730 'abstract class <name> { <block> }',
1731 'abstract class <name>',
1732 'abstract class (<signature>) { <block> }',
1733 'abstract class { <block> }',
1734 'abstract class;',
1735 $ref,
1736 );
1737
1738 1 my ($pos, $plus, $name, $version, $sig, $compact_extends, $compact_with, $block) = ($+[0], $+{plus}, $+{name}, $+{version}, $+{sig}, $+{compact_extends}, $+{compact_with},$+{block});
1739 1 my $has_sig = !!exists $+{sig};
1740 1 ▶ $plus ||= '';
Condition50%1/2
$plus ||= ""
l!l
01
MC/DC0%0/1
$plus ||= ""
$plus
Truth table50%1/2
A
A= $plus
Aresult
11
00
1741 1 ▶ $block ||= '{}';
Condition50%1/2
$block ||= "{}"
l!l
01
MC/DC0%0/1
$block ||= "{}"
$block
Truth table50%1/2
A
A= $block
Aresult
11
00
1742
1743 1 $me->_inject($ref, $pos, $me->_handle_package_keyword(abstract => $name, $version, $compact_extends, $compact_with, $block, $has_sig, $sig, $plus, \%opts), 1);
1744 39 ▶ } if $want{abstract};
Branch: 1 branch
BranchTrueFalseTotal
if $want{"abstract"} 39 0 39
1745  
1746 39 for my $kw (qw/ role interface /) {
1747 Keyword::Simple::define $kw => sub {
1748 19 ▶ my $ref = shift;
Subroutine __ANON__: called CC=3 SCAR=11.2
1749
1750 19 ▶ $$ref =~ _fetch_re('MxpRoleSyntax', anchor => 'start') or $me->_syntax_error(
Branch: 1 branch
BranchTrueFalseTotal
$$ref =~ _fetch_re("MxpRoleSyntax", "anchor", "start") or $me->_syntax_error("$kw declaration", "$kw <name> (<signature>) { <block> }", "$kw <name> { <block> }", "$kw <name>", "$kw (<signature>) { <block> }", "$kw { <block> }", "$kw;", $ref) 0 19 19
1751 "$kw declaration",
1752 "$kw <name> (<signature>) { <block> }",
1753 "$kw <name> { <block> }",
1754 "$kw <name>",
1755 "$kw (<signature>) { <block> }",
1756 "$kw { <block> }",
1757 "$kw;",
1758 $ref,
1759 );
1760
1761 19 my ($pos, $name, $version, $sig, $compact_extends, $compact_with, $block) = ($+[0], $+{name}, $+{version}, $+{sig}, $+{compact_extends}, $+{compact_with}, $+{block});
1762 19 my $has_sig = !!exists $+{sig};
1763 19 ▶ $block ||= '{}';
Condition50%1/2
$block ||= "{}"
l!l
190
MC/DC0%0/1
$block ||= "{}"
$block
Truth table50%1/2
A
A= $block
Aresult
11
00
1764
1765 19 $me->_inject($ref, $pos, $me->_handle_package_keyword($kw => $name, $version, $compact_extends, $compact_with, $block, $has_sig, $sig, '', \%opts), 1);
1766 78 ▶ } if $want{$kw};
Branch: 1 branch
BranchTrueFalseTotal
if $want{$kw} 78 0 78
1767 }
1768  
1769 Keyword::Simple::define toolkit => sub {
1770 0 ▶ my $ref = shift;
Subroutine __ANON__: not called CC=7 SCAR=37.6
1771
1772 0 ▶ $$ref =~ _fetch_re('MxpToolkitSyntax', anchor => 'start') or $me->_syntax_error(
Branch: 1 branch
BranchTrueFalseTotal
$$ref =~ _fetch_re("MxpToolkitSyntax", "anchor", "start") or $me->_syntax_error("toolkit declaration", "toolkit <toolkit> (<extensions>)", "toolkit <toolkit>;", $ref) 0 0 0
1773 'toolkit declaration',
1774 'toolkit <toolkit> (<extensions>)',
1775 'toolkit <toolkit>;',
1776 $ref,
1777 );
1778
1779 0 my ($pos, $name, $imports) = ($+[0], $+{name}, $+{imports});
1780
1781 0 ▶ if ($imports) {
Branch: 1 branch
BranchTrueFalseTotal
if ($imports) { } 0 0 0
1782 0 my @imports = grep defined,
1783 ($imports =~ / ((?&PerlQualifiedIdentifier)|(?&PerlComma)) $GRAMMAR /xg);
1784 0 my @processed_imports;
1785 0 ▶ while (@imports) {
Branch: 1 branch
BranchTrueFalseTotal
if (@imports) 0 0 0
1786 32 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1787 0 my $next = shift @imports;
1788 0 ▶ if ($next =~ /^::(.+)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($next =~ /^::(.+)$/u) { } 0 0 0
elsif ($next =~ /^[^\W0-9]/u) { } 0 0 0
1789 0 push @processed_imports, $1;
1790 }
1791 elsif ($next =~ /^[^\W0-9]/) {
1792 0 push @processed_imports, sprintf('%sX::%s', $name, $next);
1793 }
1794 else {
1795 0 require Carp;
1796 0 Carp::croak("Expected package name, got $next");
1797 }
1798 0 ▶ $imports[0] eq ',' and shift @imports;
Branch: 1 branch
BranchTrueFalseTotal
$imports[0] eq "," and shift @imports 0 0 0
1799 }
1800 0 $me->_inject($ref, $pos, sprintf('q[%s]->_toolkit(%s);', $me, join ",", map(B::perlstring($_), $name, @processed_imports)));
1801 }
1802
1803 else {
1804 0 $me->_inject($ref, $pos, sprintf('q[%s]->_toolkit(%s);', $me, B::perlstring($name)));
1805 }
1806 39 ▶ } if $want{toolkit};
Branch: 1 branch
BranchTrueFalseTotal
if $want{"toolkit"} 39 0 39
1807  
1808 # `begin`, `end`, `before_apply`, and `after_apply` keywords
1809 #
1810 39 my %injections = (
1811 begin => [ '$package,$kind', '' ],
1812 end => [ '$package,$kind', '' ],
1813 before_apply => [ '$role,$package', 'my $kind = "Role::Hooks"->is_role($package)?"role":"class";' ],
1814 after_apply => [ '$role,$package', 'my $kind = "Role::Hooks"->is_role($package)?"role":"class";' ],
1815 );
1816 39 for my $kw (qw/ begin end before_apply after_apply /) {
1817 Keyword::Simple::define $kw => sub {
1818 5 ▶ my $ref = shift;
Subroutine __ANON__: called CC=2 SCAR=7.0
1819
1820 5 ▶ $$ref =~ _fetch_re('MxpHookSyntax', anchor => 'start') or $me->_syntax_error(
Branch: 1 branch
BranchTrueFalseTotal
$$ref =~ _fetch_re("MxpHookSyntax", "anchor", "start") or $me->_syntax_error("$kw hook", "$kw { <block> }", $ref) 0 5 5
1821 "$kw hook",
1822 "$kw { <block> }",
1823 $ref,
1824 );
1825
1826 5 my ($pos, $capture) = ($+[0], $+{hook});
1827 5 my $inj = sprintf('q[%s]->_%s(sub { my (%s) = @_; %s; do %s });', $me, $kw, $injections{$kw}[0], $injections{$kw}[1], $capture);
1828 5 $me->_inject($ref, $pos, $inj);
1829 156 ▶ } if $want{$kw};
Branch: 1 branch
BranchTrueFalseTotal
if $want{$kw} 156 0 156
1830 }
1831
1832 # `type_name` keyword
1833 #
1834 Keyword::Simple::define type_name => sub {
1835 1 ▶ my $ref = shift;
Subroutine __ANON__: called CC=2 SCAR=7.0
1836
1837 1 ▶ $$ref =~ _fetch_re('MxpTypeNameSyntax', anchor => 'start') or $me->_syntax_error(
Branch: 1 branch
BranchTrueFalseTotal
$$ref =~ _fetch_re("MxpTypeNameSyntax", "anchor", "start") or $me->_syntax_error("type name declaration", "type_name <identifier>", $ref) 0 1 1
1838 'type name declaration',
1839 'type_name <identifier>',
1840 $ref,
1841 );
1842
1843 1 my ($pos, $capture) = ($+[0], $+{name});
1844 1 $me->_inject($ref, $pos, sprintf('q[%s]->_type_name(%s);', $me, B::perlstring($capture)));
1845 39 ▶ } if $want{type_name};
Branch: 1 branch
BranchTrueFalseTotal
if $want{"type_name"} 39 0 39
1846
1847 # `extends` keyword
1848 #
1849 Keyword::Simple::define extends => sub {
1850 6 ▶ my $ref = shift;
Subroutine __ANON__: called CC=2 SCAR=7.0
1851
1852 6 ▶ $$ref =~ _fetch_re('MxpExtendsSyntax', anchor => 'start') or $me->_syntax_error(
Branch: 1 branch
BranchTrueFalseTotal
$$ref =~ _fetch_re("MxpExtendsSyntax", "anchor", "start") or $me->_syntax_error("extends declaration", "extends <classes>", $ref) 0 6 6
1853 'extends declaration',
1854 'extends <classes>',
1855 $ref,
1856 );
1857
1858 6 my ($pos, $capture) = ($+[0], $+{list});
1859 6 $me->_inject($ref, $pos, sprintf('q[%s]->_extends(%s);', $me, $me->_handle_role_list($capture, 'class')));
1860 39 ▶ } if $want{extends};
Branch: 1 branch
BranchTrueFalseTotal
if $want{"extends"} 39 0 39
1861
1862 # `with` keyword
1863 #
1864 Keyword::Simple::define with => sub {
1865 13 ▶ my $ref = shift;
Subroutine __ANON__: called CC=2 SCAR=7.0
1866
1867 13 ▶ $$ref =~ _fetch_re('MxpWithSyntax', anchor => 'start') or $me->_syntax_error(
Branch: 1 branch
BranchTrueFalseTotal
$$ref =~ _fetch_re("MxpWithSyntax", "anchor", "start") or $me->_syntax_error("with declaration", "with <roles>", $ref) 0 13 13
1868 'with declaration',
1869 'with <roles>',
1870 $ref,
1871 );
1872
1873 13 my ($pos, $capture) = ($+[0], $+{list});
1874
1875 13 $me->_inject($ref, $pos, sprintf('q[%s]->_with(%s);', $me, $me->_handle_role_list($capture, 'role')));
1876 39 ▶ } if $want{with};
Branch: 1 branch
BranchTrueFalseTotal
if $want{"with"} 39 0 39
1877
1878 # `requires` keyword
1879 #
1880 Keyword::Simple::define requires => sub {
1881 3 ▶ my $ref = shift;
Subroutine __ANON__: called CC=2 SCAR=7.0
1882
1883 3 ▶ $$ref =~ _fetch_re('MxpRequiresSyntax', anchor => 'start') or $me->_syntax_error(
Branch: 1 branch
BranchTrueFalseTotal
$$ref =~ _fetch_re("MxpRequiresSyntax", "anchor", "start") or $me->_syntax_error("requires declaration", "requires <name> (<signature>)", "requires <name>", $ref) 0 3 3
1884 'requires declaration',
1885 'requires <name> (<signature>)',
1886 'requires <name>',
1887 $ref,
1888 );
1889
1890 3 my ($pos, $name, $sig) = ($+[0], $+{name}, $+{sig});
1891 3 my $has_sig = !!exists $+{sig};
1892 3 $me->_inject($ref, $pos, $me->_handle_requires_keyword($name, $has_sig, $sig));
1893 39 ▶ } if $want{requires};
Branch: 1 branch
BranchTrueFalseTotal
if $want{"requires"} 39 0 39
1894
1895 # `has`, `field`, and `param` keyword
1896 #
1897 39 for my $kw ( qw/ has field param / ) {
1898 Keyword::Simple::define $kw => sub {
1899 33 ▶ my $ref = shift;
Subroutine __ANON__: called CC=4 SCAR=13.9
1900
1901 33 ▶ $$ref =~ _fetch_re('MxpHasSyntax', anchor => 'start') or $me->_syntax_error(
Branch: 1 branch
BranchTrueFalseTotal
$$ref =~ _fetch_re("MxpHasSyntax", "anchor", "start") or $me->_syntax_error("attribute declaration", "$kw <names> (<spec>) = <default>", "$kw <names> (<spec>)", "$kw <names> = <default>", "$kw <names>", $ref) 0 33 33
1902 'attribute declaration',
1903 "$kw <names> (<spec>) = <default>",
1904 "$kw <names> (<spec>)",
1905 "$kw <names> = <default>",
1906 "$kw <names>",
1907 $ref,
1908 );
1909
1910 33 my ($pos, $name, $spec, $default) = ($+[0], $+{name}, $+{spec}, $+{default});
1911 33 my $has_spec = !!exists $+{spec};
1912 33 my $has_default = !!exists $+{default};
1913 33 ▶ $me->_inject($ref, $pos, $me->_handle_has_keyword($kw, $name, $has_spec ? $spec : undef, $has_default ? $default : undef));
Branch: 2 branches
BranchTrueFalseTotal
$has_spec ? : 19 14 33
$has_default ? : 6 27 33
1914 117 ▶ } if $want{$kw};
Branch: 1 branch
BranchTrueFalseTotal
if $want{$kw} 117 0 117
1915 }
1916
1917 # `constant` keyword
1918 #
1919 Keyword::Simple::define constant => sub {
1920 8 ▶ my $ref = shift;
Subroutine __ANON__: called CC=2 SCAR=7.0
1921
1922 8 ▶ $$ref =~ _fetch_re('MxpConstantSyntax', anchor => 'start') or $me->_syntax_error(
Branch: 1 branch
BranchTrueFalseTotal
$$ref =~ _fetch_re("MxpConstantSyntax", "anchor", "start") or $me->_syntax_error("constant declaration", "constant <name> = <value>", $ref) 0 8 8
1923 'constant declaration',
1924 'constant <name> = <value>',
1925 $ref,
1926 );
1927
1928 8 my ($pos, $name, $expr) = ($+[0], $+{name}, $+{expr});
1929 8 $me->_inject($ref, $pos, sprintf('q[%s]->_constant(%s, %s);', $me, B::perlstring($name), $expr));
1930 39 ▶ } if $want{constant};
Branch: 1 branch
BranchTrueFalseTotal
if $want{"constant"} 39 0 39
1931
1932 # `method` keyword
1933 #
1934 Keyword::Simple::define method => sub {
1935 25 ▶ my $ref = shift;
Subroutine __ANON__: called CC=3 SCAR=11.0
1936
1937 25 state $re_attr = _fetch_re('MxpAttribute');
1938
1939 25 ▶ $$ref =~ _fetch_re('MxpMethodSyntax', anchor => 'start') or $me->_syntax_error(
Branch: 1 branch
BranchTrueFalseTotal
$$ref =~ _fetch_re("MxpMethodSyntax", "anchor", "start") or $me->_syntax_error("method declaration", "method <name> <attributes> (<signature>) { <block> }", "method <name> (<signature>) { <block> }", "method <name> <attributes> { <block> }", "method <name> { <block> }", "method <attributes> (<signature>) { <block> }", "method (<signature>) { <block> }", "method <attributes> { <block> }", "method { <block> }", $ref) 0 25 25
1940 'method declaration',
1941 'method <name> <attributes> (<signature>) { <block> }',
1942 'method <name> (<signature>) { <block> }',
1943 'method <name> <attributes> { <block> }',
1944 'method <name> { <block> }',
1945 'method <attributes> (<signature>) { <block> }',
1946 'method (<signature>) { <block> }',
1947 'method <attributes> { <block> }',
1948 'method { <block> }',
1949 $ref,
1950 );
1951
1952 25 my ($pos, $name, $attributes, $sig, $code) = ($+[0], $+{name}, $+{attributes}, $+{sig}, $+{code});
1953 25 my $has_sig = !!exists $+{sig};
1954 25 ▶ my @attrs = $attributes ? grep(defined, ( ($attributes) =~ /($re_attr)/xg )) : ();
Branch: 1 branch
BranchTrueFalseTotal
$attributes ? : 3 22 25
1955
1956 25 $me->_inject($ref, $pos, $me->_handle_method_keyword(method => $name, $code, $has_sig, $sig, \@attrs));
1957 39 ▶ } if $want{method};
Branch: 1 branch
BranchTrueFalseTotal
if $want{"method"} 39 0 39
1958  
1959 # `symmethod` keyword
1960 #
1961 Keyword::Simple::define symmethod => sub {
1962 7 ▶ my $ref = shift;
Subroutine __ANON__: called CC=3 SCAR=11.0
1963
1964 7 state $re_attr = _fetch_re('MxpAttribute');
1965
1966 7 ▶ $$ref =~ _fetch_re('MxpSymMethodSyntax', anchor => 'start') or $me->_syntax_error(
Branch: 1 branch
BranchTrueFalseTotal
$$ref =~ _fetch_re("MxpSymMethodSyntax", "anchor", "start") or $me->_syntax_error("symmethod declaration", "symmethod <name> <attributes> (<signature>) { <block> }", "symmethod <name> (<signature>) { <block> }", "symmethod <name> <attributes> { <block> }", "symmethod <name> { <block> }", $ref) 0 7 7
1967 'symmethod declaration',
1968 'symmethod <name> <attributes> (<signature>) { <block> }',
1969 'symmethod <name> (<signature>) { <block> }',
1970 'symmethod <name> <attributes> { <block> }',
1971 'symmethod <name> { <block> }',
1972 $ref,
1973 );
1974
1975 7 my ($pos, $name, $attributes, $sig, $code) = ($+[0], $+{name}, $+{attributes}, $+{sig}, $+{code});
1976 7 my $has_sig = !!exists $+{sig};
1977 7 ▶ my @attrs = $attributes ? grep(defined, ( ($attributes) =~ /($re_attr)/xg )) : ();
Branch: 1 branch
BranchTrueFalseTotal
$attributes ? : 1 6 7
1978
1979 7 $me->_inject($ref, $pos, $me->_handle_method_keyword(symmethod => $name, $code, $has_sig, $sig, \@attrs));
1980 39 ▶ } if $want{symmethod};
Branch: 1 branch
BranchTrueFalseTotal
if $want{"symmethod"} 39 0 39
1981  
1982 # `multi` keyword
1983 #
1984 Keyword::Simple::define multi => sub {
1985 16 ▶ my $ref = shift;
Subroutine __ANON__: called CC=3 SCAR=11.0
1986
1987 16 state $re_attr = _fetch_re('MxpAttribute');
1988
1989 16 ▶ $$ref =~ _fetch_re('MxpMultiSyntax', anchor => 'start') or $me->_syntax_error(
Branch: 1 branch
BranchTrueFalseTotal
$$ref =~ _fetch_re("MxpMultiSyntax", "anchor", "start") or $me->_syntax_error("multimethod declaration", "multi method <name> <attributes> (<signature>) { <block> }", "multi method <name> (<signature>) { <block> }", "multi method <name> <attributes> { <block> }", "multi method <name> { <block> }", "multi factory <name> <attributes> (<signature>) { <block> }", "multi factory <name> (<signature>) { <block> }", "multi factory <name> <attributes> { <block> }", "multi factory <name> { <block> }", $ref) 0 16 16
1990 'multimethod declaration',
1991 'multi method <name> <attributes> (<signature>) { <block> }',
1992 'multi method <name> (<signature>) { <block> }',
1993 'multi method <name> <attributes> { <block> }',
1994 'multi method <name> { <block> }',
1995 'multi factory <name> <attributes> (<signature>) { <block> }',
1996 'multi factory <name> (<signature>) { <block> }',
1997 'multi factory <name> <attributes> { <block> }',
1998 'multi factory <name> { <block> }',
1999 $ref,
2000 );
2001
2002 16 my ($pos, $kind, $name, $attributes, $sig, $code) = ($+[0], $+{kind}, $+{name}, $+{attributes}, $+{sig}, $+{code});
2003 16 my $has_sig = !!exists $+{sig};
2004 16 ▶ my @attrs = $attributes ? grep(defined, ( ($attributes) =~ /($re_attr)/xg )) : ();
Branch: 1 branch
BranchTrueFalseTotal
$attributes ? : 2 14 16
2005
2006 16 $me->_inject($ref, $pos, $me->_handle_multi_keyword($kind, $name, $code, $has_sig, $sig, \@attrs));
2007 39 ▶ } if $want{multi};
Branch: 1 branch
BranchTrueFalseTotal
if $want{"multi"} 39 0 39
2008  
2009 # `before`, `after`, and `around` keywords
2010 #
2011 39 for my $kw (qw( before after around )) {
2012 Keyword::Simple::define $kw => sub {
2013 3 ▶ my $ref = shift;
Subroutine __ANON__: called CC=3 SCAR=11.2
2014
2015 3 state $re_attr = _fetch_re('MxpAttribute');
2016
2017 3 ▶ $$ref =~ _fetch_re('MxpModifierSyntax', anchor => 'start') or $me->_syntax_error(
Branch: 1 branch
BranchTrueFalseTotal
$$ref =~ _fetch_re("MxpModifierSyntax", "anchor", "start") or $me->_syntax_error("$kw method modifier declaration", "$kw <names> <attributes> (<signature>) { <block> }", "$kw <names> (<signature>) { <block> }", "$kw <names> <attributes> { <block> }", "$kw <names> { <block> }", $ref) 0 3 3
2018 "$kw method modifier declaration",
2019 "$kw <names> <attributes> (<signature>) { <block> }",
2020 "$kw <names> (<signature>) { <block> }",
2021 "$kw <names> <attributes> { <block> }",
2022 "$kw <names> { <block> }",
2023 $ref,
2024 );
2025
2026 3 my ($pos, $name, $attributes, $sig, $code) = ($+[0], $+{name}, $+{attributes}, $+{sig}, $+{code});
2027 3 my $has_sig = !!exists $+{sig};
2028 3 ▶ my @attrs = $attributes ? grep(defined, ( ($attributes) =~ /($re_attr)/xg )) : ();
Branch: 1 branch
BranchTrueFalseTotal
$attributes ? : 0 3 3
2029
2030 3 $me->_inject($ref, $pos, $me->_handle_modifier_keyword($kw, $name, $code, $has_sig, $sig, \@attrs));
2031 117 ▶ } if $want{$kw};
Branch: 1 branch
BranchTrueFalseTotal
if $want{$kw} 117 0 117
2032 }
2033
2034 Keyword::Simple::define factory => sub {
2035 3 ▶ my $ref = shift;
Subroutine __ANON__: called CC=5 SCAR=16.3
2036
2037 3 ▶ if ( $$ref =~ _fetch_re('MxpFactorySyntax', anchor => 'start') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$ref =~ _fetch_re("MxpFactorySyntax", "anchor", "start")) 2 1 3
2038 2 state $re_attr = _fetch_re('MxpAttribute');
2039 2 my ($pos, $name, $attributes, $sig, $code) = ($+[0], $+{name}, $+{attributes}, $+{sig}, $+{code});
2040 2 my $has_sig = !!exists $+{sig};
2041 2 ▶ my @attrs = $attributes ? grep(defined, ( ($attributes) =~ /($re_attr)/xg )) : ();
Branch: 1 branch
BranchTrueFalseTotal
$attributes ? : 0 2 2
2042 2 $me->_inject($ref, $pos, $me->_handle_factory_keyword($name, undef, $code, $has_sig, $sig, \@attrs));
2043 2 return;
2044 }
2045
2046 1 ▶ $$ref =~ _fetch_re('MxpFactoryViaSyntax', anchor => 'start') or $me->_syntax_error(
Branch: 1 branch
BranchTrueFalseTotal
$$ref =~ _fetch_re("MxpFactoryViaSyntax", "anchor", "start") or $me->_syntax_error("factory method declaration", "factory <name> <attributes> (<signature>) { <block> }", "factory <name> (<signature>) { <block> }", "factory <name> <attributes> { <block> }", "factory <name> { <block> }", "factory <name> via <methodname>", "factory <name>", $ref) 0 1 1
2047 'factory method declaration',
2048 'factory <name> <attributes> (<signature>) { <block> }',
2049 'factory <name> (<signature>) { <block> }',
2050 'factory <name> <attributes> { <block> }',
2051 'factory <name> { <block> }',
2052 'factory <name> via <methodname>',
2053 'factory <name>',
2054 $ref,
2055 );
2056
2057 1 my ($pos, $name, $via) = ($+[0], $+{name}, $+{via});
2058 1 ▶ $via ||= 'new';
Condition50%1/2
$via ||= "new"
l!l
10
MC/DC0%0/1
$via ||= "new"
$via
Truth table50%1/2
A
A= $via
Aresult
11
00
2059
2060 1 $me->_inject($ref, $pos, $me->_handle_factory_keyword($name, $via, undef, undef, undef, []));
2061 39 ▶ } if $want{factory};
Branch: 1 branch
BranchTrueFalseTotal
if $want{"factory"} 39 0 39
2062
2063 Keyword::Simple::define coerce => sub {
2064 1 ▶ my $ref = shift;
Subroutine __ANON__: called CC=7 SCAR=22.4
2065
2066 1 ▶ $$ref =~ _fetch_re('MxpCoerceSyntax', anchor => 'start') or $me->_syntax_error(
Branch: 1 branch
BranchTrueFalseTotal
$$ref =~ _fetch_re("MxpCoerceSyntax", "anchor", "start") or $me->_syntax_error("coercion declaration", "coerce from <type> via <method_name> { <block> }", "coerce from <type> via <method_name>", $ref) 0 1 1
2067 'coercion declaration',
2068 'coerce from <type> via <method_name> { <block> }',
2069 'coerce from <type> via <method_name>',
2070 $ref,
2071 );
2072
2073 1 my ($pos, $from, $via, $code) = ($+[0], $+{from}, $+{via}, $+{code});
2074 1 ▶ if ($from =~ /^\{/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($from =~ /^\{/u) { } 0 1 1
elsif (not $from =~ /^(q\b)|(qq\b)|"|'/u) { } 1 0 1
2075 0 $from = "scalar(do $from)"
2076 }
2077 elsif ($from !~ /^(q\b)|(qq\b)|"|'/) {
2078 1 $from = B::perlstring($from);
2079 }
2080 1 ▶ if ($via =~ /^\{/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($via =~ /^\{/u) { } 0 1 1
elsif (not $via =~ /^(q\b)|(qq\b)|"|'/u) { } 1 0 1
2081 0 $via = "scalar(do $via)"
2082 }
2083 elsif ($via !~ /^(q\b)|(qq\b)|"|'/) {
2084 1 $via = B::perlstring($via);
2085 }
2086
2087 1 ▶ $me->_inject($ref, $pos, sprintf('q[%s]->_coerce(%s, %s, %s);', $me, $from, $via, $code ? "sub { my \$class; local \$_; (\$class, \$_) = \@_; do $code }" : ''));
Branch: 1 branch
BranchTrueFalseTotal
$code ? : 1 0 1
2088 39 ▶ } if $want{coerce};
Branch: 1 branch
BranchTrueFalseTotal
if $want{"coerce"} 39 0 39
2089
2090 # Go!
2091 #
2092 on_scope_end {
2093 32 ▶ eval "package $caller; use Zydeco::_Gather -go; 1"
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
eval "package $caller; use Zydeco::_Gather -go; 1" or Carp::croak($@) 4 35 39
2094 or Carp::croak($@);
2095 39 };
2096
2097 # Need this to export `authority` and `version`...
2098 39 @_ = ($me);
2099 39 push @_, grep $want{$_}, @Zydeco::EXPORT;
2100 39 goto \&Exporter::Tiny::import;
2101 }
2102  
2103 31 our $TARGET;
2104 31 our $EVENT;
2105  
2106 sub _package_callback {
2107 98 ▶ shift;
Subroutine _package_callback: called CC=2 SCAR=6.9
2108 98 my %args;
2109 98 ▶ while ( not is_CodeRef $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_CodeRef($_[0])) 83 98 181
2110 83 my ( $k, $v ) = splice @_, 0, 2;
2111 83 $args{$k} = $v;
2112 }
2113 98 my $cb = shift;
2114 98 local $TARGET = \%args;
2115 98 &$cb;
2116 98 return \%args;
2117 }
2118  
2119 sub _define_or_patch (&;$) {
2120 130 ▶ my ($do, $fallback) = @_;
Subroutine _define_or_patch: called CC=7 SCAR=19.9
2121
2122 130 my $is_patching = 0;
2123 130 ▶ if ( is_HashRef $TARGET ) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_HashRef($Zydeco::TARGET)) { } 121 9 130
elsif (is_Str($Zydeco::TARGET) or is_Str($fallback)) { } 9 0 9
2124 121 $_ = $TARGET;
2125 }
2126 ▶ elsif ( is_Str $TARGET or is_Str $fallback ) {
Condition66%2/3
is_Str($Zydeco::TARGET) or is_Str($fallback)
l!l&&r!l&&!r
270
MC/DC0%0/2
is_Str($Zydeco::TARGET) or is_Str($fallback)
is_Str($Zydeco::TARGET) is_Str($fallback)
Truth table66%2/3
A or B
A= is_Str($Zydeco::TARGET)B= is_Str($fallback)
ABresult
1X1
011
000
2127 9 $_ = {};
2128 9 $is_patching = 1;
2129 }
2130 else {
2131 0 return;
2132 }
2133
2134 130 $do->();
2135
2136 130 ▶ if ( $is_patching ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_patching) 9 121 130
2137 9 ▶ my %got = 'MooX::Press'->patch_package( $TARGET||$fallback, %$_ );
Condition66%2/3
$Zydeco::TARGET || $fallback
l!l&&r!l&&!r
270
MC/DC0%0/2
$Zydeco::TARGET || $fallback
$Zydeco::TARGET $fallback
Truth table66%2/3
A || B
A= $Zydeco::TARGETB= $fallback
ABresult
1X1
011
000
2138 9 ▶ return if keys %got;
Branch: 1 branch
BranchTrueFalseTotal
if keys %got 0 9 9
2139 }
2140
2141 130 return 1;
2142 }
2143  
2144 sub _define_do_not_patch (&) {
2145 24 ▶ my $do = shift;
Subroutine _define_do_not_patch: called CC=2 SCAR=7.2
2146 24 ▶ if ( is_HashRef $TARGET ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_HashRef($Zydeco::TARGET)) { } 24 0 24
2147 24 $_ = $TARGET;
2148 }
2149 else {
2150 0 return 0;
2151 }
2152 24 $do->();
2153 24 return 1;
2154 }
2155  
2156 # `version` keyword
2157 #
2158 sub version {
2159 2 ▶ my $ver = shift;
Subroutine version: called CC=2 SCAR=7.1
Pod documented
2160 2 ▶ _define_or_patch { $_->{version} = $ver } or
Subroutine __ANON__: called CC=1 SCAR=0.0
2161 2 ▶ __PACKAGE__->_syntax_error('version declaration', 'Not supported outside class or role');
Branch: 1 branch
BranchTrueFalseTotal
&_define_or_patch(sub { $_->{"version"} = $ver; } ) or __PACKAGE__->_syntax_error("version declaration", "Not supported outside class or role") 0 2 2
2162 }
2163  
2164 # `authority` keyword
2165 #
2166 sub authority {
2167 0 ▶ my $auth = shift;
Subroutine authority: not called CC=2 SCAR=17.9
Pod documented
2168 0 ▶ _define_or_patch { $_->{authority} = $auth } or
Subroutine __ANON__: not called CC=1 SCAR=6.9
2169 0 ▶ __PACKAGE__->_syntax_error('authority declaration', 'Not supported outside class or role');
Branch: 1 branch
BranchTrueFalseTotal
&_define_or_patch(sub { $_->{"authority"} = $auth; } ) or __PACKAGE__->_syntax_error("authority declaration", "Not supported outside class or role") 0 0 0
2170 }
2171  
2172 # `overload` keyword
2173 #
2174 sub overload {
2175 1 ▶ my @args = @_;
Subroutine overload: called CC=6 SCAR=24.1
Pod documented
2176 1 ▶ if (@_ == 1 and ref($_[0]) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'HASH') { } 0 1 1
elsif (@_ == 1 and ref $_[0] eq 'ARRAY') { } 0 2 2
Condition33%1/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
100
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
2177 0 @args = %{+shift};
2178 }
2179 ▶ elsif (@_ == 1 and ref($_[0]) eq 'ARRAY') {
Condition33%1/3
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
100
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] eq "ARRAY"
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
2180 0 @args = @{+shift};
2181 }
2182
2183 1 ▶ _define_or_patch { push @{$_->{overload}||=[]}, @args } or
Subroutine __ANON__: called CC=2 SCAR=7.2
Condition50%1/2
$_->{"overload"} ||= []
l!l
01
MC/DC0%0/1
$_->{"overload"} ||= []
$_->{"overload"}
Truth table50%1/2
A
A= $_->{"overload"}
Aresult
11
00
2184 1 ▶ __PACKAGE__->_syntax_error('overload declaration', 'Not supported outside class');
Branch: 1 branch
BranchTrueFalseTotal
&_define_or_patch(sub { push @{$_->{"overload"} ||= [];}, @args; } ) or __PACKAGE__->_syntax_error("overload declaration", "Not supported outside class") 0 1 1
2185 }
2186  
2187 # `Zydeco::PACKAGE_SPEC` keyword
2188 #
2189 sub PACKAGE_SPEC {
2190 1 ▶ if (is_HashRef $TARGET) {
Subroutine PACKAGE_SPEC: called CC=2 SCAR=8.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if (is_HashRef($Zydeco::TARGET)) 1 0 1
2191 1 return $TARGET;
2192 }
2193
2194 0 __PACKAGE__->_syntax_error('Zydeco::PACKAGE_SPEC() function', 'Not supported outside class or role');
2195 }
2196  
2197  
2198 #
2199 # CALLBACKS
2200 #
2201  
2202 sub _has {
2203 40 ▶ my $me = shift;
Subroutine _has: called CC=14 SCAR=35.1
2204 40 my ($attr, %spec) = @_;
2205
2206 40 ▶ my $kw = delete( $spec{_has_keyword} ) // 'has';
Condition50%1/2
delete $spec{"_has_keyword"} // "has"
l!l
400
MC/DC0%0/1
delete $spec{"_has_keyword"} // "has"
delete $spec{"_has_keyword"}
Truth table50%1/2
A
A= delete $spec{"_has_keyword"}
Aresult
11
00
2207 40 ▶ if ( $kw eq 'param' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($kw eq 'param') { } 2 38 40
elsif ($kw eq 'field') { } 1 37 38
2208 2 ▶ unless ( exists $spec{default} or exists $spec{builder} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $spec{"default"} or exists $spec{"builder"}) 0 2 2
Condition33%1/3
exists $spec{"default"} or exists $spec{"builder"}
l!l&&r!l&&!r
200
MC/DC0%0/2
exists $spec{"default"} or exists $spec{"builder"}
exists $spec{"default"} exists $spec{"builder"}
Truth table33%1/3
A or B
A= exists $spec{"default"}B= exists $spec{"builder"}
ABresult
1X1
011
000
2209 0 ▶ $spec{required} //= 1;
Condition0%0/2
$spec{"required"} //= 1
l!l
00
MC/DC0%0/1
$spec{"required"} //= 1
$spec{"required"}
Truth table0%0/2
A
A= $spec{"required"}
Aresult
11
00
2210 }
2211 }
2212 elsif ( $kw eq 'field' ) {
2213 1 ▶ $spec{init_arg} //= undef;
Condition50%1/2
$spec{"init_arg"} //= undef
l!l
01
MC/DC0%0/1
$spec{"init_arg"} //= undef
$spec{"init_arg"}
Truth table50%1/2
A
A= $spec{"init_arg"}
Aresult
11
00
2214 1 ▶ if ( defined( my $init_arg = $spec{init_arg} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $init_arg = $spec{"init_arg"})) 0 1 1
2215 0 ▶ $init_arg =~ /\A_/ or
Branch: 1 branch
BranchTrueFalseTotal
$init_arg =~ /\A_/u or $me->_syntax_error("attribute declaration", "If init_arg for field is defined, must start with underscore") 0 0 0
2216 $me->_syntax_error('attribute declaration', 'If init_arg for field is defined, must start with underscore');
2217 }
2218 1 ▶ if ( !exists $spec{default} and !exists $spec{builder} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $spec{"default"} or exists $spec{"builder"}) 0 1 1
Condition33%1/3
exists $spec{"default"} or exists $spec{"builder"}
l!l&&r!l&&!r
100
MC/DC0%0/2
exists $spec{"default"} or exists $spec{"builder"}
exists $spec{"default"} exists $spec{"builder"}
Truth table33%1/3
A or B
A= exists $spec{"default"}B= exists $spec{"builder"}
ABresult
1X1
011
000
2219 0 ▶ $spec{is} //= 'rwp';
Condition0%0/2
$spec{"is"} //= "rwp"
l!l
00
MC/DC0%0/1
$spec{"is"} //= "rwp"
$spec{"is"}
Truth table0%0/2
A
A= $spec{"is"}
Aresult
11
00
2220 }
2221 }
2222
2223 40 ▶ _define_or_patch { $_->{has}{$attr} = \%spec } or
Subroutine __ANON__: called CC=1 SCAR=0.0
2224 40 ▶ $me->_syntax_error('attribute declaration', 'Not supported outside class or role');
Branch: 1 branch
BranchTrueFalseTotal
&_define_or_patch(sub { $_->{"has"}{$attr} = \%spec; } ) or $me->_syntax_error("attribute declaration", "Not supported outside class or role") 0 40 40
2225 }
2226  
2227 sub _extends {
2228 13 ▶ my $me = shift;
Subroutine _extends: called CC=2 SCAR=7.1
2229 13 my @classes = @_;
2230
2231 13 ▶ _define_do_not_patch { @{ $_->{extends}||=[] } = @classes } or
Subroutine __ANON__: called CC=2 SCAR=7.2
Condition50%1/2
$_->{"extends"} ||= []
l!l
013
MC/DC0%0/1
$_->{"extends"} ||= []
$_->{"extends"}
Truth table50%1/2
A
A= $_->{"extends"}
Aresult
11
00
2232 13 ▶ $me->_syntax_error('extends declaration', 'Not supported outside class');
Branch: 1 branch
BranchTrueFalseTotal
&_define_do_not_patch(sub { @{$_->{"extends"} ||= [];} = @classes; } ) or $me->_syntax_error("extends declaration", "Not supported outside class") 0 13 13
2233 }
2234  
2235 sub _type_name {
2236 1 ▶ my $me = shift;
Subroutine _type_name: called CC=2 SCAR=7.0
2237 1 my ($name) = @_;
2238
2239 1 ▶ _define_do_not_patch { $_->{type_name} = $name } or
Subroutine __ANON__: called CC=1 SCAR=0.0
2240 1 ▶ $me->_syntax_error('extends declaration', 'Not supported outside class or role');
Branch: 1 branch
BranchTrueFalseTotal
&_define_do_not_patch(sub { $_->{"type_name"} = $name; } ) or $me->_syntax_error("extends declaration", "Not supported outside class or role") 0 1 1
2241 }
2242  
2243 sub _begin {
2244 1 ▶ my $me = shift;
Subroutine _begin: called CC=2 SCAR=7.0
2245 1 my ($coderef) = @_;
2246
2247 _define_do_not_patch {
2248 my $wrapped_coderef = sub {
2249 1 ▶ local $TARGET = $_[0];
Subroutine __ANON__: called CC=1 SCAR=0.0
2250 1 local $EVENT = 'begin';
2251 1 &$coderef;
2252 1 ▶ };
Subroutine __ANON__: called CC=2 SCAR=7.1
2253 1 ▶ push @{$_->{begin}||=[]}, $wrapped_coderef;
Condition50%1/2
$_->{"begin"} ||= []
l!l
01
MC/DC0%0/1
$_->{"begin"} ||= []
$_->{"begin"}
Truth table50%1/2
A
A= $_->{"begin"}
Aresult
11
00
2254 } or
2255 1 ▶ $me->_syntax_error('begin hook', 'Not supported outside class or role (use import option instead)');
Branch: 1 branch
BranchTrueFalseTotal
&_define_do_not_patch(sub { my $wrapped_coderef = sub { local $TARGET = $_[0]; local $EVENT = "begin"; &$coderef; } ; push @{$_->{"begin"} ||= [];}, $wrapped_coderef; } ) or $me->_syntax_error("begin hook", "Not supported outside class or role (use import option instead)") 0 1 1
2256 }
2257  
2258 sub _end {
2259 1 ▶ my $me = shift;
Subroutine _end: called CC=2 SCAR=7.0
2260 1 my ($coderef) = @_;
2261
2262 _define_do_not_patch {
2263 my $wrapped_coderef = sub {
2264 1 ▶ local $TARGET = $_[0];
Subroutine __ANON__: called CC=1 SCAR=0.0
2265 1 local $EVENT = 'end';
2266 1 &$coderef;
2267 1 ▶ };
Subroutine __ANON__: called CC=2 SCAR=7.1
2268 1 ▶ push @{$_->{end}||=[]}, $wrapped_coderef;
Condition50%1/2
$_->{"end"} ||= []
l!l
01
MC/DC0%0/1
$_->{"end"} ||= []
$_->{"end"}
Truth table50%1/2
A
A= $_->{"end"}
Aresult
11
00
2269 } or
2270 1 ▶ $me->_syntax_error('end hook', 'Not supported outside class or role (use import option instead)');
Branch: 1 branch
BranchTrueFalseTotal
&_define_do_not_patch(sub { my $wrapped_coderef = sub { local $TARGET = $_[0]; local $EVENT = "end"; &$coderef; } ; push @{$_->{"end"} ||= [];}, $wrapped_coderef; } ) or $me->_syntax_error("end hook", "Not supported outside class or role (use import option instead)") 0 1 1
2271 }
2272  
2273 sub _before_apply {
2274 2 ▶ my $me = shift;
Subroutine _before_apply: called CC=2 SCAR=7.0
2275 2 my ($coderef) = @_;
2276
2277 _define_do_not_patch {
2278 my $wrapped_coderef = sub {
2279 3 ▶ local $TARGET = $_[1];
Subroutine __ANON__: called CC=1 SCAR=0.0
2280 3 local $EVENT = 'before_apply';
2281 3 &$coderef;
2282 2 ▶ };
Subroutine __ANON__: called CC=2 SCAR=7.0
2283 2 ▶ push @{$_->{before_apply}||=[]}, $wrapped_coderef;
Condition50%1/2
$_->{"before_apply"} ||= []
l!l
02
MC/DC0%0/1
$_->{"before_apply"} ||= []
$_->{"before_apply"}
Truth table50%1/2
A
A= $_->{"before_apply"}
Aresult
11
00
2284 2 return;
2285 } or
2286 2 ▶ $me->_syntax_error('before_apply hook', 'Not supported outside role');
Branch: 1 branch
BranchTrueFalseTotal
&_define_do_not_patch(sub { my $wrapped_coderef = sub { local $TARGET = $_[1]; local $EVENT = "before_apply"; &$coderef; } ; push @{$_->{"before_apply"} ||= [];}, $wrapped_coderef; return; } ) or $me->_syntax_error("before_apply hook", "Not supported outside role") 0 2 2
2287 }
2288  
2289 sub _after_apply {
2290 2 ▶ my $me = shift;
Subroutine _after_apply: called CC=2 SCAR=7.0
2291 2 my ($coderef) = @_;
2292
2293 _define_do_not_patch {
2294 my $wrapped_coderef = sub {
2295 3 ▶ local $TARGET = $_[1];
Subroutine __ANON__: called CC=1 SCAR=0.0
2296 3 local $EVENT = 'after_apply';
2297 3 &$coderef;
2298 2 ▶ };
Subroutine __ANON__: called CC=2 SCAR=7.0
2299 2 ▶ push @{$_->{after_apply}||=[]}, $wrapped_coderef;
Condition50%1/2
$_->{"after_apply"} ||= []
l!l
02
MC/DC0%0/1
$_->{"after_apply"} ||= []
$_->{"after_apply"}
Truth table50%1/2
A
A= $_->{"after_apply"}
Aresult
11
00
2300 2 return;
2301 } or
2302 2 ▶ $me->_syntax_error('after_apply hook', 'Not supported outside role');
Branch: 1 branch
BranchTrueFalseTotal
&_define_do_not_patch(sub { my $wrapped_coderef = sub { local $TARGET = $_[1]; local $EVENT = "after_apply"; &$coderef; } ; push @{$_->{"after_apply"} ||= [];}, $wrapped_coderef; return; } ) or $me->_syntax_error("after_apply hook", "Not supported outside role") 0 2 2
2303 }
2304  
2305 sub _interface {
2306 0 ▶ my $me = shift;
Subroutine _interface: not called CC=2 SCAR=17.9
2307 0 my ($arg) = @_;
2308
2309 0 ▶ _define_do_not_patch { $_->{interface} = $arg } or
Subroutine __ANON__: not called CC=1 SCAR=6.9
2310 0 ▶ $me->_syntax_error('interface callback', 'Not supported outside role');
Branch: 1 branch
BranchTrueFalseTotal
&_define_do_not_patch(sub { $_->{"interface"} = $arg; } ) or $me->_syntax_error("interface callback", "Not supported outside role") 0 0 0
2311 }
2312  
2313 sub _abstract {
2314 1 ▶ my $me = shift;
Subroutine _abstract: called CC=2 SCAR=7.0
2315 1 my ($arg) = @_;
2316
2317 1 ▶ _define_do_not_patch { $_->{abstract} = $arg } or
Subroutine __ANON__: called CC=1 SCAR=0.0
2318 1 ▶ $me->_syntax_error('abstract callback', 'Not supported outside class');
Branch: 1 branch
BranchTrueFalseTotal
&_define_do_not_patch(sub { $_->{"abstract"} = $arg; } ) or $me->_syntax_error("abstract callback", "Not supported outside class") 0 1 1
2319 }
2320  
2321 sub _with {
2322 19 ▶ my $me = shift;
Subroutine _with: called CC=2 SCAR=7.1
2323 19 my @roles = @_;
2324
2325 19 ▶ _define_or_patch { push @{ $_->{with}||=[] }, @roles } or
Subroutine __ANON__: called CC=2 SCAR=7.2
Condition50%1/2
$_->{"with"} ||= []
l!l
019
MC/DC0%0/1
$_->{"with"} ||= []
$_->{"with"}
Truth table50%1/2
A
A= $_->{"with"}
Aresult
11
00
2326 19 ▶ $me->_syntax_error('with declaration', 'Not supported outside class or role');
Branch: 1 branch
BranchTrueFalseTotal
&_define_or_patch(sub { push @{$_->{"with"} ||= [];}, @roles; } ) or $me->_syntax_error("with declaration", "Not supported outside class or role") 0 19 19
2327 }
2328  
2329 sub _toolkit {
2330 0 ▶ my $me = shift;
Subroutine _toolkit: not called CC=2 SCAR=17.9
2331 0 my ($toolkit, @imports) = @_;
2332
2333 _define_do_not_patch {
2334 0 ▶ $_->{toolkit} = $toolkit;
Subroutine __ANON__: not called CC=3 SCAR=24.8
2335 0 ▶ push @{ $_->{import}||=[] }, @imports if @imports;
Branch: 1 branch
BranchTrueFalseTotal
if @imports 0 0 0
Condition0%0/2
$_->{"import"} ||= []
l!l
00
MC/DC0%0/1
$_->{"import"} ||= []
$_->{"import"}
Truth table0%0/2
A
A= $_->{"import"}
Aresult
11
00
2336 } or
2337 0 ▶ $me->_syntax_error('toolkit declaration', 'Not supported outside class or role (use import option instead)');
Branch: 1 branch
BranchTrueFalseTotal
&_define_do_not_patch(sub { $_->{"toolkit"} = $toolkit; push @{$_->{"import"} ||= [];}, @imports if @imports; } ) or $me->_syntax_error("toolkit declaration", "Not supported outside class or role (use import option instead)") 0 0 0
2338 }
2339  
2340 sub _requires {
2341 3 ▶ my $me = shift;
Subroutine _requires: called CC=2 SCAR=7.0
2342 3 my @names = @_;
2343
2344 3 ▶ _define_do_not_patch { push @{ $_->{requires}||=[] }, @names } or
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$_->{"requires"} ||= []
l!l
12
MC/DC100%1/1
$_->{"requires"} ||= []
$_->{"requires"}
Truth table100%2/2
A
A= $_->{"requires"}
Aresult
11
00
2345 3 ▶ $me->_syntax_error('requires declaration', 'Not supported outside role');
Branch: 1 branch
BranchTrueFalseTotal
&_define_do_not_patch(sub { push @{$_->{"requires"} ||= [];}, @names; } ) or $me->_syntax_error("requires declaration", "Not supported outside role") 0 3 3
2346 }
2347  
2348 sub _coerce {
2349 1 ▶ my $me = shift;
Subroutine _coerce: called CC=2 SCAR=7.1
2350 1 my @args = @_;
2351
2352 1 ▶ _define_or_patch { push @{$_->{coerce}||=[]}, @args } or
Subroutine __ANON__: called CC=2 SCAR=7.2
Condition50%1/2
$_->{"coerce"} ||= []
l!l
01
MC/DC0%0/1
$_->{"coerce"} ||= []
$_->{"coerce"}
Truth table50%1/2
A
A= $_->{"coerce"}
Aresult
11
00
2353 1 ▶ $me->_syntax_error('coercion declaration', 'Not supported outside class');
Branch: 1 branch
BranchTrueFalseTotal
&_define_or_patch(sub { push @{$_->{"coerce"} ||= [];}, @args; } ) or $me->_syntax_error("coercion declaration", "Not supported outside class") 0 1 1
2354 }
2355  
2356 sub _factory {
2357 3 ▶ my $me = shift;
Subroutine _factory: called CC=2 SCAR=7.0
2358 3 my @args = @_;
2359
2360 3 ▶ _define_or_patch { push @{$_->{factory}||=[]}, @args } scalar(caller) or
Subroutine __ANON__: called CC=2 SCAR=7.0
Branch: 1 branch
BranchTrueFalseTotal
&_define_or_patch(sub { push @{$_->{"factory"} ||= [];}, @args; } , scalar caller) or $me->_syntax_error("factory method declaration", "Not supported outside class") 0 3 3
Condition100%2/2
$_->{"factory"} ||= []
l!l
12
MC/DC100%1/1
$_->{"factory"} ||= []
$_->{"factory"}
Truth table100%2/2
A
A= $_->{"factory"}
Aresult
11
00
2361 $me->_syntax_error('factory method declaration', 'Not supported outside class');
2362 }
2363  
2364 sub _constant {
2365 12 ▶ my $me = shift;
Subroutine _constant: called CC=2 SCAR=7.0
2366 12 my ($name, $value) = @_;
2367
2368 12 ▶ _define_or_patch { $_->{constant}{$name} = $value } scalar(caller) or die;
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
&_define_or_patch(sub { $_->{"constant"}{$name} = $value; } , scalar caller) or die 0 12 12
2369 }
2370  
2371 sub _can {
2372 24 ▶ my $me = shift;
Subroutine _can: called CC=2 SCAR=7.0
2373 24 my ($name, $code) = @_;
2374
2375 24 ▶ _define_or_patch { $_->{can}{$name} = $code } scalar(caller) or die;
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
&_define_or_patch(sub { $_->{"can"}{$name} = $code; } , scalar caller) or die 0 24 24
2376 }
2377  
2378 sub _symmethod {
2379 7 ▶ my $me = shift;
Subroutine _symmethod: called CC=5 SCAR=16.2
2380 7 my ($name, $code) = @_;
2381
2382 7 my @new_attr;
2383 my $order;
2384 7 for my $attr ( @{ $code->{attributes} } ) {
2385 1 ▶ if ( $attr =~ /^order\((.+)\)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attr =~ /^order\((.+)\)$/u) { } 1 0 1
2386 1 $order = $1;
2387 }
2388 else {
2389 0 push @new_attr, $attr;
2390 }
2391 }
2392
2393 7 ▶ if ( defined $order ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $order) 1 6 7
2394 1 $code->{attributes} = \@new_attr;
2395 1 $code->{order} = $order;
2396 }
2397
2398 7 ▶ _define_or_patch { push @{$_->{symmethod}||=[]}, $name, $code } scalar(caller) or die;
Subroutine __ANON__: called CC=2 SCAR=7.0
Branch: 1 branch
BranchTrueFalseTotal
&_define_or_patch(sub { push @{$_->{"symmethod"} ||= [];}, $name, $code; } , scalar caller) or die 0 7 7
Condition100%2/2
$_->{"symmethod"} ||= []
l!l
25
MC/DC100%1/1
$_->{"symmethod"} ||= []
$_->{"symmethod"}
Truth table100%2/2
A
A= $_->{"symmethod"}
Aresult
11
00
2399 }
2400  
2401 sub _multi {
2402 16 ▶ my $me = shift;
Subroutine _multi: called CC=3 SCAR=11.0
2403 16 my ($kind, $name, $spec) = @_;
2404
2405 16 ▶ if ($kind eq 'factory') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq 'factory') { } 2 14 16
2406 2 ▶ _define_or_patch { push @{$_->{multifactory}||=[]}, $name, $spec } or
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$_->{"multifactory"} ||= []
l!l
11
MC/DC100%1/1
$_->{"multifactory"} ||= []
$_->{"multifactory"}
Truth table100%2/2
A
A= $_->{"multifactory"}
Aresult
11
00
2407 2 ▶ $me->_syntax_error('multi factory method declaration', 'Not supported outside class');
Branch: 1 branch
BranchTrueFalseTotal
&_define_or_patch(sub { push @{$_->{"multifactory"} ||= [];}, $name, $spec; } ) or $me->_syntax_error("multi factory method declaration", "Not supported outside class") 0 2 2
2408 }
2409 else {
2410 14 ▶ _define_or_patch { push @{$_->{multimethod}||=[]}, $name, $spec } scalar(caller);
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$_->{"multimethod"} ||= []
l!l
212
MC/DC100%1/1
$_->{"multimethod"} ||= []
$_->{"multimethod"}
Truth table100%2/2
A
A= $_->{"multimethod"}
Aresult
11
00
2411 }
2412 }
2413  
2414 sub _modifier {
2415 5 ▶ my $me = shift;
Subroutine _modifier: called CC=1 SCAR=0.0
2416 5 my ($kind, @args) = @_;
2417 5 ▶ _define_or_patch { push @{$_->{$kind}||=[]}, @args } scalar(caller);
Subroutine __ANON__: called CC=2 SCAR=7.1
Condition50%1/2
$_->{$kind} ||= []
l!l
05
MC/DC0%0/1
$_->{$kind} ||= []
$_->{$kind}
Truth table50%1/2
A
A= $_->{$kind}
Aresult
11
00
2418 }
2419  
2420 sub _include {
2421 2 ▶ my $me = shift;
Subroutine _include: called CC=6 SCAR=23.1
2422 2 ▶ is_HashRef($TARGET) and $me->_syntax_error('include directive', 'Not supported inside class or role');
Branch: 1 branch
BranchTrueFalseTotal
is_HashRef($Zydeco::TARGET) and $me->_syntax_error("include directive", "Not supported inside class or role") 0 2 2
2423
2424 2 require Path::ScanINC;
2425 2 my @chunks = split /::/, $_[0];
2426 2 $chunks[-1] .= '.zydeco.pm';
2427 2 my $file = Path::ScanINC->new->first_file(@chunks);
2428
2429 2 ▶ if (!$file) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($file) 0 2 2
2430 0 my @fallback = @chunks;
2431 0 $fallback[-1] =~ s/\.zydeco\.pm$/.pl/;
2432 0 $file = Path::ScanINC->new->first_file(@fallback);
2433 0 ▶ if ($file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file) 0 0 0
2434 0 require Carp;
2435 0 Carp::carp("Include .pl deprecated, use .zydeco.pm instead. Loaded: " . join("/", @fallback));
2436 }
2437 }
2438
2439 2 ▶ if (!$file) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($file) 0 2 2
2440 0 require Carp;
2441 0 Carp::croak("No such file: " . join("/", @chunks));
2442 }
2443
2444 2 ▶ ref $file eq 'ARRAY' and die "not supported yet";
Branch: 1 branch
BranchTrueFalseTotal
ref $file eq "ARRAY" and die "not supported yet" 0 2 2
2445 2 my $code = $file->slurp_utf8;
2446
2447 2 sprintf(
2448 "do {\n# line 1 %s\n%s\n};\n1;\n",
2449 B::perlstring($file),
2450 $code,
2451 );
2452 }
2453  
2454 #{
2455 # package Zydeco::Anonymous::Package;
2456 # our $AUTHORITY = 'cpan:TOBYINK';
2457 # our $VERSION = '0.616';
2458 # use overload q[""] => sub { ${$_[0]} }, fallback => 1;
2459 # sub DESTROY {}
2460 # sub AUTOLOAD {
2461 # my $me = shift;
2462 # (my $method = our $AUTOLOAD) =~ s/.*:://;
2463 # $$me->$method(@_);
2464 # }
2465 #
2466 # package Zydeco::Anonymous::Class;
2467 # our $AUTHORITY = 'cpan:TOBYINK';
2468 # our $VERSION = '0.616';
2469 # our @ISA = qw(Zydeco::Anonymous::Package);
2470 # sub new {
2471 # my $me = shift;
2472 # $$me->new(@_);
2473 # }
2474 # use overload q[&{}] => sub {
2475 # my $me = shift;
2476 # sub { $me->new(@_) }
2477 # };
2478 #
2479 # package Zydeco::Anonymous::Role;
2480 # our $AUTHORITY = 'cpan:TOBYINK';
2481 # our $VERSION = '0.616';
2482 # our @ISA = qw(Zydeco::Anonymous::Package);
2483 #
2484 # package Zydeco::Anonymous::ParameterizableClass;
2485 # our $AUTHORITY = 'cpan:TOBYINK';
2486 # our $VERSION = '0.616';
2487 # our @ISA = qw(Zydeco::Anonymous::Package);
2488 # sub generate_package {
2489 # my $me = shift;
2490 # my $gen = $$me->generate_package(@_);
2491 # bless \$gen, 'Zydeco::Anonymous::Class';
2492 # }
2493 # use overload q[&{}] => sub {
2494 # my $me = shift;
2495 # sub { $me->new_class(@_) }
2496 # };
2497 #
2498 # package Zydeco::Anonymous::ParameterizableRole;
2499 # our $AUTHORITY = 'cpan:TOBYINK';
2500 # our $VERSION = '0.616';
2501 # our @ISA = qw(Zydeco::Anonymous::Package);
2502 # sub generate_package {
2503 # my $me = shift;
2504 # my $gen = $$me->generate_package(@_);
2505 # bless \$gen, 'Zydeco::Anonymous::Class';
2506 # }
2507 # use overload q[&{}] => sub {
2508 # my $me = shift;
2509 # sub { $me->new_role(@_) }
2510 # };
2511 #}
2512  
2513 31 my $i = 0;
2514 sub anonymous_package {
2515 4 ▶ my $me = shift;
Subroutine anonymous_package: called CC=3 SCAR=11.0
Pod undocumented
2516 4 my ($kind, $callback, %opts) = @_;
2517 4 my $package_dfn = $me->_package_callback($callback);
2518
2519 4 for my $forbidden (qw/ factory type_name coerce /) {
2520 12 ▶ die if exists $package_dfn->{$forbidden};
Branch: 1 branch
BranchTrueFalseTotal
if exists $package_dfn->{$forbidden} 0 12 12
2521 }
2522 4 $package_dfn->{type_name} = undef;
2523 4 $package_dfn->{factory} = undef;
2524
2525 4 my $qname = sprintf('%s::__ANON_%06d__', __PACKAGE__, ++$i);
2526
2527 4 require MooX::Press;
2528 4 my $method = "make_$kind";
2529 4 MooX::Press->$method(MooX::Press::make_absolute_package_name($qname), %opts, %$package_dfn);
2530
2531 4 require Module::Runtime;
2532 4 $INC{Module::Runtime::module_notional_filename($qname)} = __FILE__;
2533 #return bless(\$qname, "Zydeco::Anonymous::".ucfirst($kind));
2534 4 return MooX::Press::make_absolute_package_name($qname);
2535 }
2536  
2537 sub anonymous_generator {
2538 1 ▶ my $me = shift;
Subroutine anonymous_generator: called CC=1 SCAR=0.0
Pod undocumented
2539 1 my ($kind, $callback, %opts) = @_;
2540 1 my $qname = sprintf('%s::__ANON_%06d__', __PACKAGE__, ++$i);
2541
2542 1 require MooX::Press;
2543 1 my $method = "make_$kind\_generator";
2544 1 MooX::Press->$method(MooX::Press::make_absolute_package_name($qname), %opts, generator => $callback);
2545
2546 1 require Module::Runtime;
2547 1 $INC{Module::Runtime::module_notional_filename($qname)} = __FILE__;
2548 #return bless(\$qname, "Zydeco::Anonymous::Parameterizable".ucfirst($kind));
2549 1 return MooX::Press::make_absolute_package_name($qname);
2550 }
2551  
2552 31 1;
2553  
2554 __END__
2555  
2556 =pod
2557  
2558 =encoding utf-8
2559  
2560 =head1 NAME
2561  
2562 Zydeco - Jazz up your Perl
2563  
2564 =head1 SYNOPSIS
2565  
2566 MyApp.pm
2567  
2568 use v5.14;
2569 use strict;
2570 use warnings;
2571
2572 package MyApp {
2573 use Zydeco;
2574
2575 class Person {
2576 has name ( type => Str, required => true );
2577 has gender ( type => Str );
2578
2579 factory new_man (Str $name) {
2580 return $class->new(name => $name, gender => 'male');
2581 }
2582
2583 factory new_woman (Str $name) {
2584 return $class->new(name => $name, gender => 'female');
2585 }
2586
2587 method greet (Person *friend, Str *greeting = "Hello") {
2588 printf("%s, %s!\n", $arg->greeting, $arg->friend->name);
2589 }
2590
2591 coerce from Str via from_string {
2592 return $class->new(name => $_);
2593 }
2594 }
2595 }
2596  
2597 my_script.pl
2598  
2599 use v5.14;
2600 use strict;
2601 use warnings;
2602 use MyApp;
2603 use MyApp::Types qw( is_Person );
2604
2605 # Create a new MyApp::Person object.
2606 #
2607 my $alice = MyApp->new_woman("Alice");
2608 is_Person($alice) or die;
2609
2610 # The string "Bob" will be coerced to a MyApp::Person.
2611 #
2612 $alice->greet(friend => "Bob", greeting => 'Hi');
2613  
2614 =head1 DESCRIPTION
2615  
2616 Zydeco is a Perl module to jazz up your object-oriented programming.
2617 It fuses together:
2618  
2619 =over
2620  
2621 =item *
2622  
2623 Classes, roles, and interfaces
2624  
2625 =item *
2626  
2627 Powerful and concise attribute definitions
2628  
2629 =item *
2630  
2631 Methods with signatures, type constraints, and coercion
2632  
2633 =item *
2634  
2635 Factories to help your objects make other objects
2636  
2637 =item *
2638  
2639 Multimethods
2640  
2641 =item *
2642  
2643 Method modifiers to easily wrap or override inherited methods
2644  
2645 =item *
2646  
2647 Powerful delegation features
2648  
2649 =item *
2650  
2651 True private methods and attributes
2652  
2653 =item *
2654  
2655 Parameterizable classes and roles
2656  
2657 =item *
2658  
2659 Syntactic sugar as sweet as pecan pie
2660  
2661 =back
2662  
2663 L<Zydeco::Manual> is probably the best place to start.
2664  
2665 If Zydeco is too slow or has too many dependencies for you, check out
2666 L<Zydeco::Lite>.
2667  
2668 =head1 KEYWORDS
2669  
2670 =head2 C<< class >>
2671  
2672 class MyClass;
2673
2674 class MyClass { ... }
2675
2676 class BaseClass {
2677 class SubClass;
2678 }
2679
2680 class MyGenerator (@args) { ... }
2681 my $class = MyApp->generate_mygenerator(...);
2682
2683 my $class = do { class; };
2684
2685 my $class = do { class { ... } };
2686
2687 my $generator = do { class (@args) { ... } };
2688 my $class = $generator->generate_package(...);
2689  
2690 =head2 C<< abstract class >>
2691  
2692 abstract class MyClass;
2693
2694 abstract class MyClass { ... }
2695
2696 abstract class BaseClass {
2697 class SubClass;
2698 }
2699
2700 my $class = do { abstract class; };
2701
2702 my $class = do { abstract class { ... } };
2703
2704 =head2 C<< role >>
2705  
2706 role MyRole;
2707
2708 role MyRole { ... }
2709
2710 role MyGenerator (@args) { ... }
2711 my $role = MyApp->generate_mygenerator(...);
2712
2713 my $role = do { role; };
2714
2715 my $role = do { role { ... } };
2716
2717 my $generator = do { role (@args) { ... } };
2718 my $role = $generator->generate_package(...);
2719  
2720 =head2 C<< interface >>
2721  
2722 interface MyIface;
2723
2724 interface MyIface { ... }
2725
2726 interface MyGenerator (@args) { ... }
2727 my $interface = MyApp->generate_mygenerator(...);
2728
2729 my $iface = do { interface; };
2730
2731 my $iface = do { interface { ... } };
2732
2733 my $generator = do { interface (@args) { ... } };
2734 my $iface = $generator->generate_package(...);
2735  
2736 =head2 C<< toolkit >>
2737  
2738 class MyClass {
2739 toolkit Moose;
2740 }
2741
2742 class MyClass {
2743 toolkit Mouse;
2744 }
2745
2746 class MyClass {
2747 toolkit Moo;
2748 }
2749
2750 class MyClass {
2751 toolkit Moose (StrictConstructor);
2752 }
2753  
2754 Modules in parentheses are prefixed by C<< "$toolkit\::X" >> unless they start
2755 with "::" and loaded. Not all modules are useful to load this way because they
2756 are loaded too late to have a lexical effect, and because code inside the
2757 class will not be able to see functions exported into the class.
2758  
2759 =head2 C<< extends >>
2760  
2761 class MyClass extends BaseClass;
2762
2763 class MyClass extends BaseClass, OtherClass;
2764
2765 class MyClass {
2766 extends BaseClass;
2767 }
2768
2769 class MyClass {
2770 extends BaseClass, OtherClass;
2771 }
2772  
2773 =head2 C<< with >>
2774  
2775 class MyClass with SomeRole;
2776
2777 class MyClass with SomeRole, OtherRole;
2778
2779 class MyClass extends BaseClass with SomeRole, OtherRole;
2780
2781 class MyClass {
2782 with SomeRole;
2783 }
2784
2785 class MyClass {
2786 with SomeRole, OtherRole;
2787 }
2788
2789 class MyClass {
2790 with RoleGenerator(@args), OtherRole;
2791 }
2792
2793 class MyClass {
2794 with TagRole?, OtherTagRole?;
2795 }
2796
2797 role MyRole {
2798 with OtherRole;
2799 }
2800
2801 role MyRole with OtherRole {
2802 ...;
2803 }
2804
2805 role MyRole with SomeRole, OtherRole;
2806  
2807 =head2 C<< begin >>
2808  
2809 class MyClass {
2810 begin { say "defining $kind $package"; }
2811 }
2812
2813 role MyRole {
2814 begin { say "defining $kind $package"; }
2815 }
2816  
2817 =head2 C<< end >>
2818  
2819 class MyClass {
2820 end { say "finished defining $kind $package"; }
2821 }
2822
2823 role MyRole {
2824 end { say "finished defining $kind $package"; }
2825 }
2826  
2827 =head2 C<< before_apply >>
2828  
2829 role MyRole {
2830 before_apply { say "applying $role to $package"; }
2831 }
2832  
2833 =head2 C<< after_apply >>
2834  
2835 role MyRole {
2836 after_apply { say "finished applying $role to $package"; }
2837 }
2838  
2839 =head2 C<< has >>
2840  
2841 class MyClass {
2842 has foo;
2843 }
2844
2845 class MyClass {
2846 has foo;
2847 class MySubClass {
2848 has +foo;
2849 }
2850 }
2851
2852 class MyClass {
2853 has foo, bar;
2854 }
2855
2856 class MyClass {
2857 has foo!, bar;
2858 }
2859
2860 class MyClass {
2861 has { "fo" . "o" };
2862 }
2863
2864 class MyClass {
2865 has $foo; # private attribute withg lexical accessor
2866 }
2867
2868 class MyClass {
2869 has foo ( is => ro, type => Int, default => 1 ) ;
2870 }
2871
2872 class MyClass {
2873 has name = "Anonymous";
2874 has uc_name = uc($self->name);
2875 }
2876  
2877 =head2 C<< param >>
2878  
2879 Synonym for C<has> but defaults to C<< required => true >>.
2880  
2881 class MyClass {
2882 param foo ( type => Str );
2883 }
2884  
2885 =head2 C<< field >>
2886  
2887 Synonym for C<has> but defaults to C<< init_arg => undef >>.
2888  
2889 class MyClass {
2890 field foo ( builder => true );
2891 method _build_foo { ... }
2892 }
2893  
2894 =head2 C<< constant >>
2895  
2896 class MyClass {
2897 constant PI = 3.2;
2898 }
2899
2900 interface Serializable {
2901 requires serialize;
2902 constant PRETTY = 1;
2903 constant UTF8 = 2;
2904 constant CANONICAL = 4;
2905 }
2906  
2907 =head2 C<< method >>
2908  
2909 method myfunc {
2910 ...;
2911 }
2912
2913 method myfunc ( Int $x, ArrayRef $y ) {
2914 ...;
2915 }
2916
2917 method myfunc ( HashRef *collection, Int *index ) {
2918 ...;
2919 }
2920
2921 method myfunc :optimize ( Int $x, ArrayRef $y ) {
2922 ...;
2923 }
2924
2925 my $myfunc = do { method () {
2926 ...;
2927 }};
2928
2929 method $myfunc () { # lexical method
2930 ...;
2931 }
2932  
2933 =head2 C<< symmethod >>
2934  
2935 symmethod myfunc {
2936 ...;
2937 }
2938
2939 symmethod myfunc ( Int $x, ArrayRef $y ) {
2940 ...;
2941 }
2942
2943 =head2 C<< multi method >>
2944  
2945 multi method myfunc {
2946 ...;
2947 }
2948
2949 multi method myfunc ( Int $x, ArrayRef $y ) {
2950 ...;
2951 }
2952
2953 multi method myfunc ( HashRef *collection, Int *index ) {
2954 ...;
2955 }
2956
2957 # lexical multimethod - make sure you declare the variable first
2958 #
2959 my $otherfunc;
2960 multi method $otherfunc ( CodeRef $x ) { ... }
2961 multi method $otherfunc ( HashRef $x ) { ... }
2962  
2963 =head2 C<< requires >>
2964  
2965 role MyRole {
2966 requires serialize;
2967 requires deserialize (Str $input);
2968 }
2969  
2970 =head2 C<< before >>
2971  
2972 before myfunc {
2973 ...;
2974 }
2975
2976 before myfunc ( Int $x, ArrayRef $y ) {
2977 ...;
2978 }
2979  
2980 =head2 C<< after >>
2981  
2982 after myfunc {
2983 ...;
2984 }
2985
2986 after myfunc ( Int $x, ArrayRef $y ) {
2987 ...;
2988 }
2989  
2990 =head2 C<< around >>
2991  
2992 around myfunc {
2993 ...;
2994 my $return = $self->$next( @_[2..$#_] );
2995 ...;
2996 return $return;
2997 }
2998
2999 around myfunc ( Int $x, ArrayRef $y ) {
3000 ...;
3001 my $return = $self->$next(@_);
3002 ...;
3003 return $return;
3004 }
3005  
3006 =head2 C<< factory >>
3007  
3008 class MyThing {
3009 factory new_thing {
3010 ...;
3011 }
3012 }
3013
3014 class MyThing {
3015 factory new_thing ( Int $x, ArrayRef $y ) {
3016 ...;
3017 }
3018 }
3019
3020 class MyThing {
3021 factory new_thing ( HashRef *collection, Int *index ) {
3022 ...;
3023 }
3024 }
3025
3026 class MyThing {
3027 method _make_thing {
3028 ...;
3029 }
3030 factory new_thing via _make_thing;
3031 }
3032
3033 class MyThing {
3034 factory new_thing;
3035 }
3036  
3037 =head2 C<< multi factory >>
3038  
3039 class MyThing {
3040 multi factory new_thing ( ArrayRef $x ) {
3041 ...;
3042 }
3043
3044 multi factory new_thing ( HashRef $x ) {
3045 ...;
3046 }
3047 }
3048  
3049 =head2 C<< type_name >>
3050  
3051 class Person {
3052 type_name Hooman;
3053 }
3054
3055 role Serializer {
3056 type_name Ser;
3057 }
3058  
3059 =head2 C<< coerce >>
3060  
3061 class Widget {
3062 has id (type => Int);
3063
3064 coerce from Int via from_id {
3065 $class->new(id => $_);
3066 }
3067 }
3068
3069 class Widget {
3070 has id (type => Int);
3071
3072 coerce from Int via from_id;
3073
3074 method from_id ($id) {
3075 $class->new(id => $id);
3076 }
3077 }
3078  
3079 =head2 C<< overload >>
3080  
3081 class Person {
3082 has name (type => Str);
3083 overload(q[""] => 'name', fallback => true);
3084 }
3085  
3086 =head2 C<< version >>
3087  
3088 class MyClass 1.0;
3089
3090 class MyClass {
3091 version '1.0';
3092 }
3093  
3094  
3095 =head2 C<< authority >>
3096  
3097 class MyClass {
3098 authority 'cpan:TOBYINK';
3099 }
3100  
3101 =head2 C<< include >>
3102  
3103 package MyApp {
3104 use Zydeco;
3105 include Roles;
3106 include Classes;
3107 }
3108
3109 # MyApp/Roles.zydeco.pm
3110 role Foo;
3111 role Bar;
3112
3113 # MyApp/Classes.zydeco.pm
3114 class Foo::Bar with Foo, Bar;
3115  
3116 =head2 C<< Zydeco::PACKAGE_SPEC() >>
3117  
3118 package MyApp {
3119 use Zydeco;
3120
3121 class MyClass {
3122 has name;
3123 Zydeco::PACKAGE_SPEC()->{has}{name}{required} = true;
3124 }
3125 }
3126  
3127 =head1 IMPORTS
3128  
3129 Booleans:
3130  
3131 =over
3132  
3133 =item C<< true >>
3134  
3135 =item C<< false >>
3136  
3137 =back
3138  
3139 Attribute privacy:
3140  
3141 =over
3142  
3143 =item C<< rw >>
3144  
3145 =item C<< rwp >>
3146  
3147 =item C<< ro >>
3148  
3149 =item C<< lazy >>
3150  
3151 =item C<< bare >>
3152  
3153 =item C<< private >>
3154  
3155 =back
3156  
3157 Utilities:
3158  
3159 =over
3160  
3161 =item C<< blessed($var) >>
3162  
3163 =item C<< confess($format, @args) >>
3164  
3165 =back
3166  
3167 Types:
3168  
3169 use Types::Standard qw( -types -is -assert );
3170 use Types::Common::Numeric qw( -types -is -assert );
3171 use Types::Common::String qw( -types -is -assert );
3172  
3173 Pragmas:
3174  
3175 use strict;
3176 use warnings;
3177
3178 # Perl 5.14 and Perl 5.16
3179 use feature qw( say state unicode_strings );
3180
3181 # Perl 5.18 or above
3182 use feature qw( say state unicode_strings
3183 unicode_eval evalbytes current_sub fc );
3184  
3185 Zydeco also imports L<Syntax::Keyword::Try>.
3186  
3187 =head2 Selective Import
3188  
3189 You can choose which parts of Zydeco you import:
3190  
3191 package MyApp {
3192 use Zydeco keywords => [qw/
3193 -booleans
3194 -privacy
3195 -utils
3196 -types
3197 -is
3198 -assert
3199 -features
3200 try
3201 class abstract role interface
3202 begin end before_apply after_apply
3203 include toolkit extends with requires
3204 has constant method multi factory before after around
3205 type_name coerce
3206 version authority overload
3207 /];
3208  
3209 =head2 Unimport
3210  
3211 C<< no Zydeco >> will clear up:
3212  
3213 class abstract role interface
3214 include toolkit begin end extends with requires
3215 has constant method multi factory before after around
3216 type_name coerce
3217 version authority overload
3218  
3219 But won't clear up things Zydeco imported for you from other packages.
3220 Use C<< no MooX::Press::Keywords >>, C<< no Types::Standard >>, etc to
3221 do that, or just use L<namespace::autoclean>.
3222  
3223 =head1 BUGS
3224  
3225 Please report any bugs to
3226 L<http://rt.cpan.org/Dist/Display.html?Queue=Zydeco>.
3227  
3228 =head1 TODO
3229  
3230 =head2 Plugin system
3231  
3232 Zydeco can often load MooX/MouseX/MooseX plugins and work
3233 fine with them, but some things won't work, like plugins that rely on
3234 being able to wrap C<has>. So it would be nice to have a plugin system
3235 that extensions can hook into.
3236  
3237 If you're interested in extending Zydeco, file a bug report about
3238 it and let's have a conversation about the best way for that to happen.
3239 I probably won't start a plugin API until someone actually wants to
3240 write a plugin, because that will give me a better idea about what kind
3241 of API is required.
3242  
3243 =head1 SEE ALSO
3244  
3245 Zydeco manual:
3246 L<Zydeco::Manual>.
3247  
3248 Zydeco website:
3249 L<http://zydeco.toby.ink/>.
3250  
3251 Less magic versions:
3252 L<Zydeco::Lite>,
3253 L<MooX::Press>.
3254 (Zydeco is just a wrapper around MooX::Press, providing a nicer syntax.
3255 Zydeco::Lite is an alternative wrapper, using less magic.)
3256  
3257 Important underlying technologies:
3258 L<Moo>, L<Type::Tiny::Manual>, L<Sub::HandlesVia>, L<Sub::MultiMethod>,
3259 L<Lexical::Accessor>, L<Syntax::Keyword::Try>, L<Role::Hooks>.
3260  
3261 Similar modules:
3262 L<Moops>, L<Kavorka>, L<Dios>, L<MooseX::Declare>.
3263  
3264 =head1 AUTHOR
3265  
3266 Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
3267  
3268 =head1 COPYRIGHT AND LICENCE
3269  
3270 This software is copyright (c) 2020-2022 by Toby Inkster.
3271  
3272 This is free software; you can redistribute it and/or modify it under
3273 the same terms as the Perl 5 programming language system itself.
3274  
3275 =head1 DISCLAIMER OF WARRANTIES
3276  
3277 THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
3278 WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
3279 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
3280  
↑ Summary MooX/Pression.pm »