Declare/Keyword/Action.pm

filter: Statementstmt 33.9% 98 / 289 Branchbran 0.0% 0 / 102 Conditioncond 0.0% 0 / 44 MC/DCmcdc 0.0% 0 / 26 Subroutinesub 63.9% 39 / 61 Podpod n/a totaltotal 26.2% 137 / 522 CC 74 SCAR 47.4
CC
74
Cov
23%
__ANON__
496.7
__ANON__
182.0
__ANON__
83.1
CRAP 114.8
↑ Summary Declare/Action/CatchValidationError.pm »
1 15 ▶use MooseX::Declare;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 15 ▶use MooseX::Role::Parameterized ();
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 15 ▶class CatalystX::Declare::Keyword::Action {
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=4.0
5  
6  
7 15 ▶ use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 15 ▶ use Perl6::Junction qw( any );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 15 ▶ use Data::Dump qw( pp );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 15 ▶ use MooseX::Types::Util qw( has_available_type_export );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 15 ▶ use Moose::Util qw( add_method_modifier ensure_all_roles );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 15 ▶ use Data::Pond qw(pond_write_datum);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 15 ▶ use Class::Inspector;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 15 ▶ use Class::MOP;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17 15 ▶ use constant STOP_PARSING => '__MXDECLARE_STOP_PARSING__';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 15 ▶ use constant UNDER_VAR => '$CatalystX::Declare::SCOPE::UNDER';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 15 ▶ use constant UNDER_STACK => '@CatalystX::Declare::SCOPE::UNDER_STACK';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 15 ▶ use aliased 'CatalystX::Declare::Action::CatchValidationError';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 15 ▶ use aliased 'CatalystX::Declare::Context::StringParsing';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 15 ▶ use aliased 'MooseX::Method::Signatures::Meta::Method';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 15 ▶ use aliased 'MooseX::MethodAttributes::Role::Meta::Method', 'AttributeRole';
Subroutine BEGIN: called CC=1 SCAR=0.0
25 15 ▶ use aliased 'MooseX::MethodAttributes::Role::Meta::Role', 'AttributeMetaRole';
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27  
28 0 ▶ method parse (Object $ctx, Str :$modifier?, Int :$skipped_declarator = 0) {
Subroutine BEGIN: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=22 SCAR=62.1
29  
30 # somewhere to put the attributes
31 0 my %attributes;
32 my @populators;
33  
34 # parse declarations
35 0 ▶ until (do { $ctx->skipspace; $ctx->peek_next_char } eq any qw( ; { } )) {
Branch: 1 branch
BranchTrueFalseTotal
unless (do { $ctx->skipspace; $ctx->peek_next_char } eq any((";", "{", "}"))) 0 0 0
36  
37 0 $ctx->skipspace;
38
39 # optional commas
40 0 ▶ if ($ctx->peek_next_char eq ',') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->peek_next_char eq ",") 0 0 0
41  
42 0 my $linestr = $ctx->get_linestr;
43 0 substr($linestr, $ctx->offset, 1) = '';
44 0 $ctx->set_linestr($linestr);
45  
46 0 next;
47 }
48  
49 # next thing should be an option name
50 my $option = (
51 $skipped_declarator
52 ? $ctx->strip_name
53 0 ▶ : do {
Branch: 2 branches
BranchTrueFalseTotal
my $option = $skipped_declarator ? $ctx->strip_name : do { $ctx->skip_declarator; ++$skipped_declarator; $ctx->declarator } or croak('Expected option token, not ' . substr($ctx->get_linestr, $ctx->offset)) 0 0 0
$skipped_declarator ? : 0 0 0
54 0 $ctx->skip_declarator;
55 0 $skipped_declarator++;
56 0 $ctx->declarator;
57 })
58 or croak "Expected option token, not " . substr($ctx->get_linestr, $ctx->offset);
59  
60 # we need to be able to handle the rest
61 0 ▶ my $handler = $self->can("_handle_${option}_option")
Branch: 1 branch
BranchTrueFalseTotal
my $handler = $self->can("_handle_${option}_option") or croak("Unknown action option: $option") 0 0 0
62 or croak "Unknown action option: $option";
63  
64 # call the handler
65 0 my $populator = $self->$handler($ctx, \%attributes);
66  
67 0 ▶ if ($populator and $populator eq STOP_PARSING) {
Branch: 1 branch
BranchTrueFalseTotal
if ($populator and $populator eq "__MXDECLARE_STOP_PARSING__") 0 0 0
Condition0%0/3
$populator and $populator eq "__MXDECLARE_STOP_PARSING__"
!ll&&!rl&&r
000
MC/DC0%0/2
$populator and $populator eq "__MXDECLARE_STOP_PARSING__"
$populator $populator eq "__MXDECLARE_STOP_PARSING__"
Truth table0%0/3
A and B
A= $populatorB= $populator eq "__MXDECLARE_STOP_PARSING__"
ABresult
0X0
100
111
68  
69 0 ▶ return $ctx->shadow(sub (&) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
70 0 my ($body) = @_;
71 0 return $body->();
72 0 });
73 }
74  
75 0 ▶ push @populators, $populator
Branch: 1 branch
BranchTrueFalseTotal
if defined $populator 0 0 0
76 if defined $populator;
77 }
78  
79 croak "Need an action specification"
80 0 ▶ unless exists $attributes{Signature};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $attributes{"Signature"} 0 0 0
81  
82 0 my $name = $attributes{Subname};
83  
84 0 ▶ if ($attributes{Private}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attributes{"Private"}) 0 0 0
85 0 ▶ $attributes{Signature} ||= '@';
Condition0%0/2
$attributes{"Signature"} ||= "\@"
l!l
00
MC/DC0%0/1
$attributes{"Signature"} ||= "\@"
$attributes{"Signature"}
Truth table0%0/2
A
A= $attributes{"Signature"}
Aresult
11
00
86 }
87  
88 0 my $method = Method->wrap(
89 signature => qq{($attributes{Signature})},
90 package_name => $ctx->get_curstash_name,
91 name => $name,
92 );
93  
94 0 AttributeRole->meta->apply($method);
95  
96 0 my $count = $self->_count_positional_arguments($method);
97 0 ▶ $attributes{CaptureArgs} = $count
Branch: 1 branch
BranchTrueFalseTotal
if defined $count 0 0 0
98 if defined $count;
99  
100 $_->($method)
101 0 for @populators;
102  
103 0 ▶ unless ($attributes{Private}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($attributes{"Private"}) 0 0 0
104 0 ▶ $attributes{PathPart} ||= $name;
Condition0%0/3
$attributes{"PathPart"} ||= $name
l!l&&r!l&&!r
000
MC/DC0%0/2
$attributes{"PathPart"} ||= $name
$attributes{"PathPart"} $name
Truth table0%0/3
A ||= B
A= $attributes{"PathPart"}B= $name
ABresult
1X1
011
000
105  
106 delete $attributes{CaptureArgs}
107 0 ▶ if exists $attributes{Args};
Branch: 1 branch
BranchTrueFalseTotal
if exists $attributes{"Args"} 0 0 0
108  
109 $attributes{CaptureArgs} = 0
110 unless exists $attributes{Args}
111 0 ▶ or exists $attributes{CaptureArgs};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $attributes{"Args"} or exists $attributes{"CaptureArgs"} 0 0 0
Condition0%0/3
exists $attributes{"Args"} or exists $attributes{"CaptureArgs"}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $attributes{"Args"} or exists $attributes{"CaptureArgs"}
exists $attributes{"Args"} exists $attributes{"CaptureArgs"}
Truth table0%0/3
A or B
A= exists $attributes{"Args"}B= exists $attributes{"CaptureArgs"}
ABresult
1X1
011
000
112 }
113  
114 0 ▶ if ($attributes{Private}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attributes{"Private"}) 0 0 0
115 delete $attributes{ $_ }
116 0 for qw( Args CaptureArgs Chained Signature Private );
117 }
118  
119 # inject a hashref for resolving runtime attribute values
120 0 $self->_inject_attributes($ctx, \%attributes);
121  
122 # our declaration is followed by a block
123 0 ▶ if ($ctx->peek_next_char eq '{') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->peek_next_char eq '{') { } 0 0 0
124 0 $ctx->inject_if_block($ctx->scope_injector_call . $method->injectable_code);
125 }
126  
127 # there is no block, so we insert one.
128 else {
129 0 $ctx->inject_code_parts_here(
130 sprintf '{ %s%s }',
131 $ctx->scope_injector_call,
132 $method->injectable_code,
133 );
134 }
135  
136 0 ▶ my $compile_attrs = sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
137 0 my $attributes = shift;;
138 0 my @attributes;
139  
140 0 for my $attr (keys %$attributes) {
141 0 my $value = $attributes->{ $attr };
142  
143 # the compiletime chained attr might contain the under global var name
144 0 ▶ next if $attr eq 'Chained' and $value eq UNDER_VAR;
Branch: 1 branch
BranchTrueFalseTotal
if $attr eq "Chained" and $value eq "\$CatalystX::Declare::SCOPE::UNDER" 0 0 0
Condition0%0/3
$attr eq "Chained" and $value eq "\$CatalystX::Declare::SCOPE::UNDER"
!ll&&!rl&&r
000
MC/DC0%0/2
$attr eq "Chained" and $value eq "\$CatalystX::Declare::SCOPE::UNDER"
$attr eq "Chained" $value eq "\$CatalystX::Declare::SCOPE::UNDER"
Truth table0%0/3
A and B
A= $attr eq "Chained"B= $value eq "\$CatalystX::Declare::SCOPE::UNDER"
ABresult
0X0
100
111
145  
146 push @attributes,
147 map {
148 0 ▶ my $value = ref $_ ? pond_write_datum($_) : $_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 0 0
149 0 ▶ sprintf '%s%s', $attr, defined($value) ? sprintf('(%s)', $value) : ''
Branch: 2 branches
BranchTrueFalseTotal
defined $value ? : 0 0 0
ref $value eq 'ARRAY' ? : 0 0 0
150 } (
151 ref($value) eq 'ARRAY'
152 ) ? @$value : $value;
153 }
154  
155 0 return \@attributes;
156 0 };
157  
158 0 ▶ return $ctx->shadow(sub {
Subroutine __ANON__: not called CC=13 SCAR=52.0
159 0 my $class = caller;
160 0 my $attrs = shift;
161 0 my $body = shift;
162  
163 # the runtime-resolved name
164 0 my $name = $attrs->{Subname};
165  
166 # in case no hashref was specified
167 0 ▶ $body = $attrs and $attrs = {}
Branch: 1 branch
BranchTrueFalseTotal
if ref $attrs eq "CODE" 0 0 0
Condition0%0/5
ref $attrs eq 'CODE' && (($body = $attrs) && ($attrs = {}))
!ll&&!rl&&r
000
$body = $attrs and $attrs = {}
!ll
00
MC/DC0%0/2
ref $attrs eq 'CODE' && (($body = $attrs) && ($attrs = {}))
ref $attrs eq 'CODE' $body = $attrs
Truth table0%0/3
A && B
A= ref $attrs eq 'CODE'B= $body = $attrs
ABresult
0X0
100
111
168 if ref $attrs eq 'CODE';
169  
170 # default path part to runtime-resolved name
171 0 ▶ unless ($attrs->{Private}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($attrs->{"Private"}) 0 0 0
172  
173 $attrs->{PathPart} = $attrs->{Subname}
174 0 ▶ unless defined $attrs->{PathPart};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $attrs->{"PathPart"} 0 0 0
175 }
176  
177 # in CXD we are explicit about chained values, an undefined
178 # value means we defaulted to the outer-scope under and there
179 # was none.
180 delete $attrs->{Chained}
181 0 ▶ unless defined $attrs->{Chained};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $attrs->{"Chained"} 0 0 0
182  
183 # some attrs need to be single quoted in their stringified forms
184 defined($attrs->{ $_ }) and $attrs->{ $_ } = sprintf "'%s'", $attrs->{ $_ }
185 0 ▶ for qw( Chained PathPart );
Branch: 1 branch
BranchTrueFalseTotal
defined $attrs->{$_} and $attrs->{$_} = sprintf(q['%s'], $attrs->{$_}) 0 0 0
186  
187 # merge runtime and compiletime attrs
188 0 my %full_attrs = (%attributes, %$attrs);
189 0 my $compiled_attrs = $compile_attrs->(\%full_attrs);
190 0 my $real_method = $method->reify(
191 actual_body => $body,
192 attributes => $compiled_attrs,
193 name => $name,
194 );
195  
196 # NYI
197 0 ▶ if ($modifier) {
Branch: 1 branch
BranchTrueFalseTotal
if ($modifier) { } 0 0 0
198 0 add_method_modifier $class, $modifier, [$name, $real_method];
199 }
200 else {
201  
202 0 ▶ my $prepare_meta = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
203 0 my ($meta) = @_;
204  
205 0 $meta->add_method($name, $real_method);
206 0 $meta->register_method_attributes($meta->name->can($real_method->name), $compiled_attrs);
207 0 };
208  
209 0 ▶ if ($ctx->stack->[-1] and $ctx->stack->[-1]->is_parameterized) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->stack->[-1] and $ctx->stack->[-1]->is_parameterized) { } 0 0 0
Condition0%0/3
$ctx->stack->[-1] and $ctx->stack->[-1]->is_parameterized
!ll&&!rl&&r
000
MC/DC0%0/2
$ctx->stack->[-1] and $ctx->stack->[-1]->is_parameterized
$ctx->stack->[-1] $ctx->stack->[-1]->is_parameterized
Truth table0%0/3
A and B
A= $ctx->stack->[-1]B= $ctx->stack->[-1]->is_parameterized
ABresult
0X0
100
111
210 0 my $real_meta = MooseX::Role::Parameterized->current_metaclass;
211  
212 0 ▶ $real_meta->meta->make_mutable
Branch: 1 branch
BranchTrueFalseTotal
if $real_meta->meta->is_immutable 0 0 0
213 if $real_meta->meta->is_immutable;
214 0 ▶ ensure_all_roles $real_meta->meta, AttributeMetaRole
Branch: 1 branch
BranchTrueFalseTotal
if $real_meta->isa("Moose::Meta::Role") 0 0 0
215 if $real_meta->isa('Moose::Meta::Role');
216  
217 0 $real_meta->$prepare_meta;
218 }
219 else {
220 0 $class->meta->$prepare_meta;
221 }
222 }
223 0 });
224 15 }
225  
226 0 ▶ method _handle_with_option (Object $ctx, HashRef $attrs) {
Subroutine BEGIN: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=9 SCAR=44.2
227  
228 0 my @roles_with_args = ();
229 0 push @roles_with_args, @{ $ctx->strip_names_and_args };
230  
231 # we need to fish for aliases here since we are still unclean
232 0 my @roles = ();
233 0 for my $role_with_arg(@roles_with_args) {
234 0 my ($role, $params) = @{$role_with_arg};
235 0 ▶ if($params) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params) 0 0 0
236 0 my ($first, @rest) = eval $params;
237 0 ▶ my %params = ref $first eq 'HASH' ? %$first : ($first, @rest); # both (%opts) and {%opts}
Branch: 1 branch
BranchTrueFalseTotal
ref $first eq 'HASH' ? : 0 0 0
238 0 for my $key (keys %params) {
239 0 ▶ my $value = ref $params{$key} eq 'ARRAY' ? $params{$key} : [$params{$key}];
Branch: 1 branch
BranchTrueFalseTotal
ref $params{$key} eq 'ARRAY' ? : 0 0 0
240 0 ▶ push @{ $attrs->{$key} ||=[] }, @$value;
Condition0%0/2
$attrs->{$key} ||= []
l!l
00
MC/DC0%0/1
$attrs->{$key} ||= []
$attrs->{$key}
Truth table0%0/2
A
A= $attrs->{$key}
Aresult
11
00
241 ##push @{ $attrs->{$key} ||=[] }, $params;
242  
243 }
244 }
245  
246 0 ▶ if (defined(my $alias = $self->_check_for_available_import($ctx, $role))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $alias = $self->_check_for_available_import($ctx, $role))) 0 0 0
247 0 $role = $alias;
248 }
249 0 push @roles, $role;
250 }
251  
252 0 ▶ push @{ $attrs->{CatalystX_Declarative_ActionRoles} ||= [] }, @roles;
Condition0%0/2
$attrs->{"CatalystX_Declarative_ActionRoles"} ||= []
l!l
00
MC/DC0%0/1
$attrs->{"CatalystX_Declarative_ActionRoles"} ||= []
$attrs->{"CatalystX_Declarative_ActionRoles"}
Truth table0%0/2
A
A= $attrs->{"CatalystX_Declarative_ActionRoles"}
Aresult
11
00
253 0 return;
254 15 }
255  
256 0 ▶ method _handle_isa_option (Object $ctx, HashRef $attrs) {
Subroutine BEGIN: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=3 SCAR=22.8
257  
258 0 ▶ my $class = $ctx->strip_name
Branch: 1 branch
BranchTrueFalseTotal
my $class = $ctx->strip_name or croak("Expected bareword action class specification for action after isa") 0 0 0
259 or croak "Expected bareword action class specification for action after isa";
260  
261 0 ▶ if (defined(my $alias = $self->_check_for_available_import($ctx, $class))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $alias = $self->_check_for_available_import($ctx, $class))) 0 0 0
262 0 $class = $alias;
263 }
264  
265 0 $attrs->{CatalystX_Declarative_ActionClass} = $class;
266  
267 0 return;
268 15 }
269  
270 0 ▶ method _check_for_available_import (Object $ctx, Str $name) {
Subroutine BEGIN: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=2 SCAR=15.1
271  
272 0 ▶ if (my $code = $ctx->get_curstash_name->can($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $ctx->get_curstash_name->can($name)) 0 0 0
273 0 return $code->();
274 }
275  
276 0 return undef;
277 15 }
278  
279 0 ▶ method _handle_action_option (Object $ctx, HashRef $attrs) {
Subroutine BEGIN: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=8 SCAR=42.0
280  
281 # action name
282 0 ▶ my $name = $self->_strip_actionpath($ctx, interpolate => 1)
Branch: 1 branch
BranchTrueFalseTotal
my $name = $self->_strip_actionpath($ctx, "interpolate", 1) or croak("Anonymous actions not yet supported") 0 0 0
283 or croak "Anonymous actions not yet supported";
284  
285 0 $ctx->skipspace;
286 0 my $populator;
287  
288 # shortcut under base option is basically handled by the under handler
289 0 ▶ if (substr($ctx->get_linestr, $ctx->offset, 2) eq '<-') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($ctx->get_linestr, $ctx->offset, 2) eq "<-") 0 0 0
290 0 my $linestr = $ctx->get_linestr;
291 0 substr($linestr, $ctx->offset, 2) = '';
292 0 $ctx->set_linestr($linestr);
293 0 $populator = $self->_handle_under_option($ctx, $attrs);
294 }
295  
296 # signature
297 0 ▶ my $proto = $ctx->strip_proto || '';
Condition0%0/2
$ctx->strip_proto || ''
l!l
00
MC/DC0%0/1
$ctx->strip_proto || ''
$ctx->strip_proto
Truth table0%0/2
A
A= $ctx->strip_proto
Aresult
11
00
298 0 ▶ $proto = join(', ', 'Object $self: Object $ctx', $proto || ());
Condition0%0/3
$proto || ()
l!l&&r!l&&!r
000
MC/DC0%0/2
$proto || ()
$proto ()
Truth table0%0/3
A || B
A= $protoB= ()
ABresult
1X1
011
000
299  
300 0 $attrs->{Subname} = $name;
301 0 $attrs->{Signature} = $proto;
302 0 $attrs->{Action} = [];
303  
304 0 ▶ push @{ $attrs->{CatalystX_Declarative_DefaultActionRoles} ||= [] }, CatchValidationError;
Condition0%0/2
$attrs->{"CatalystX_Declarative_DefaultActionRoles"} ||= []
l!l
00
MC/DC0%0/1
$attrs->{"CatalystX_Declarative_DefaultActionRoles"} ||= []
$attrs->{"CatalystX_Declarative_DefaultActionRoles"}
Truth table0%0/2
A
A= $attrs->{"CatalystX_Declarative_DefaultActionRoles"}
Aresult
11
00
305  
306 # default chained base to the global under var, to be resolved at runtime
307 0 ▶ $attrs->{Chained} ||= UNDER_VAR;
Condition0%0/2
$attrs->{"Chained"} ||= "\$CatalystX::Declare::SCOPE::UNDER"
l!l
00
MC/DC0%0/1
$attrs->{"Chained"} ||= "\$CatalystX::Declare::SCOPE::UNDER"
$attrs->{"Chained"}
Truth table0%0/2
A
A= $attrs->{"Chained"}
Aresult
11
00
308  
309 0 ▶ return unless $populator;
Branch: 1 branch
BranchTrueFalseTotal
unless $populator 0 0 0
310 0 return $populator;
311 15 }
312  
313 0 ▶ method _handle_final_option (Object $ctx, HashRef $attrs) {
Subroutine BEGIN: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=1 SCAR=2.6
314  
315 0 return $self->_build_flag_populator($ctx, $attrs, 'final');
316 15 }
317  
318 0 ▶ method _handle_is_option (Object $ctx, HashRef $attrs) {
Subroutine BEGIN: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=2 SCAR=14.6
319  
320 0 ▶ my $what = $ctx->strip_name
Branch: 1 branch
BranchTrueFalseTotal
my $what = $ctx->strip_name or croak('Expected symbol token after is symbol, not ' . substr($ctx->get_linestr, $ctx->offset)) 0 0 0
321 or croak "Expected symbol token after is symbol, not " . substr($ctx->get_linestr, $ctx->offset);
322  
323 0 return $self->_build_flag_populator($ctx, $attrs, $what);
324 15 }
325  
326 0 ▶ method _build_flag_populator (Object $ctx, HashRef $attrs, Str $what) {
Subroutine BEGIN: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=2 SCAR=16.5
327  
328 0 ▶ $attrs->{Private} = []
Branch: 1 branch
BranchTrueFalseTotal
if $what eq "private" 0 0 0
329 if $what eq 'private';
330  
331 0 ▶ return sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
332 0 my $method = shift;
333  
334 0 ▶ if ($what eq any qw( end endpoint final )) {
Branch: 2 branches
BranchTrueFalseTotal
if ($what eq any(('end', 'endpoint', 'final'))) { } 0 0 0
elsif ($what eq 'private') { } 0 0 0
335 0 $attrs->{Args} = delete $attrs->{CaptureArgs};
336 }
337 elsif ($what eq 'private') {
338 0 $attrs->{Private} = [];
339 }
340 0 };
341 15 }
342  
343 0 ▶ method _handle_under_option (Object $ctx, HashRef $attrs) {
Subroutine BEGIN: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=3 SCAR=23.3
344  
345 0 my $target = $self->_strip_actionpath($ctx, interpolate => 1);
346 0 $ctx->skipspace;
347  
348 0 ▶ if ($ctx->peek_next_char eq '{' and $self->identifier eq 'under') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->peek_next_char eq "{" and $self->identifier eq "under") 0 0 0
Condition0%0/3
$ctx->peek_next_char eq "{" and $self->identifier eq "under"
!ll&&!rl&&r
000
MC/DC0%0/2
$ctx->peek_next_char eq "{" and $self->identifier eq "under"
$ctx->peek_next_char eq "{" $self->identifier eq "under"
Truth table0%0/3
A and B
A= $ctx->peek_next_char eq "{"B= $self->identifier eq "under"
ABresult
0X0
100
111
349 0 $ctx->inject_if_block(
350 $ctx->scope_injector_call .
351 sprintf ';local %s = %s;',
352 UNDER_VAR,
353 $target,
354 );
355 0 return STOP_PARSING;
356 }
357  
358 0 $attrs->{Chained} = $target;
359  
360 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
361 0 my $method = shift;
362 0 };
363 15 }
364  
365 0 ▶ method _handle_chains_option (Object $ctx, HashRef $attrs) {
Subroutine BEGIN: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=2 SCAR=15.1
366  
367 0 $ctx->skipspace;
368 0 ▶ $ctx->strip_name eq 'to'
Branch: 1 branch
BranchTrueFalseTotal
$ctx->strip_name eq "to" or croak('Expected to token after chains symbol, not ' . substr($ctx->get_linestr, $ctx->offset)) 0 0 0
369 or croak "Expected to token after chains symbol, not " . substr($ctx->get_linestr, $ctx->offset);
370  
371 0 return $self->_handle_under_option($ctx, $attrs);
372 15 }
373  
374 0 ▶ method _handle_as_option (Object $ctx, HashRef $attrs) {
Subroutine BEGIN: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=1 SCAR=4.6
375  
376 0 $ctx->skipspace;
377  
378 0 my $path = $self->_strip_actionpath($ctx, interpolate => 1);
379 0 $attrs->{PathPart} = $path;
380  
381 0 return;
382 15 }
383  
384 0 ▶ method _count_positional_arguments (Object $method) {
Subroutine BEGIN: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=4 SCAR=28.5
385 0 my $signature = $method->parsed_signature;
386  
387 0 ▶ if ($signature->has_positional_params) {
Branch: 1 branch
BranchTrueFalseTotal
if ($signature->has_positional_params) 0 0 0
388 0 my $count = @{ scalar($signature->positional_params) };
389  
390 0 ▶ if ($count and ($signature->positional_params)[-1]->sigil eq '@') {
Branch: 1 branch
BranchTrueFalseTotal
if ($count and ($signature->positional_params)[-1]->sigil eq "\@") 0 0 0
Condition0%0/3
$count and ($signature->positional_params)[-1]->sigil eq "\@"
!ll&&!rl&&r
000
MC/DC0%0/2
$count and ($signature->positional_params)[-1]->sigil eq "\@"
$count ($signature->positional_params)[-1]->sigil eq "\@"
Truth table0%0/3
A and B
A= $countB= ($signature->positional_params)[-1]->sigil eq "\@"
ABresult
0X0
100
111
391 0 return undef;
392 }
393  
394 0 return $count - 1;
395 }
396  
397 0 return 0;
398 15 }
399  
400 0 ▶ method _inject_attributes (Object $ctx, HashRef $attrs) {
Subroutine BEGIN: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=2 SCAR=16.3
401  
402 # attrs that need to be runtime-resolved
403 0 my @inject = qw( Chained PathPart Subname );
404  
405 # turn specific attributes into a hashref
406 my $code = sprintf ' +{ %s }, sub ', # the ', sub ' turns method +{ ... } { ... } into
407 join ', ', # method +{ ... }, sub { ... }
408 0 map { (@$_) }
409 0 ▶ map { defined( $_->[1] ) ? $_ : [$_->[0], 'undef'] }
Branch: 1 branch
BranchTrueFalseTotal
defined $_->[1] ? : 0 0 0
410 0 map { [pp($_), $attrs->{ $_ }] }
411 0 grep { defined $attrs->{ $_ } }
412 @inject;
413  
414 # inject the hashref code before the action body
415 0 $ctx->inject_code_parts_here($code);
416 0 $ctx->inc_offset(length $code);
417 15 }
418  
419 0 ▶ method _strip_actionpath (Object $ctx, :$interpolate?) {
Subroutine BEGIN: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=5 SCAR=33.1
420  
421 0 $ctx->skipspace;
422 0 my $linestr = $ctx->get_linestr;
423 0 my $rest = substr($linestr, $ctx->offset);
424 0 ▶ my $interp = sub { $interpolate ? "'$_[0]'" : $_[0] };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$interpolate ? : 0 0 0
425  
426 # find simple barewords
427 0 ▶ if ($rest =~ /^ ( [_a-z] [_a-z0-9]* ) \b/ix) {
Branch: 3 branches
BranchTrueFalseTotal
if ($rest =~ /^ ( [_a-z] [_a-z0-9]* ) \b/xi) { } 0 0 0
elsif ($rest =~ m[^ ' ( (?:[.:;,_a-z0-9]|/)* ) ' ]xi) { } 0 0 0
elsif ($interpolate and my $str = $ctx->get_string) { } 0 0 0
428 0 substr($linestr, $ctx->offset, length($1)) = '';
429 0 $ctx->set_linestr($linestr);
430 0 return $interp->($1);
431 }
432  
433 # allow single quoted more complex barewords
434 elsif ($rest =~ /^ ' ( (?:[.:;,_a-z0-9]|\/)* ) ' /ix) {
435 0 substr($linestr, $ctx->offset, length($1) + 2) = '';
436 0 $ctx->set_linestr($linestr);
437 0 return $interp->($1);
438 }
439  
440 # double quoted strings and variables
441 ▶ elsif ($interpolate and my $str = $ctx->get_string) {
Condition0%0/3
$interpolate and my $str = $ctx->get_string
!ll&&!rl&&r
000
MC/DC0%0/2
$interpolate and my $str = $ctx->get_string
$interpolate my $str = $ctx->get_string
Truth table0%0/3
A and B
A= $interpolateB= my $str = $ctx->get_string
ABresult
0X0
100
111
442 0 return $str;
443 }
444  
445 # not suitable as action path
446 else {
447 0 croak "Invalid syntax for action path: $rest";
448 }
449 15 }
450
451 # down here because it requires the parse method
452 15 with 'MooseX::Declare::Syntax::KeywordHandling';
453  
454 0 ▶ around context_traits { $self->$orig, StringParsing }
Subroutine BEGIN: called CC=1 SCAR=1.2
Subroutine __ANON__: not called CC=1 SCAR=1.2
455 15 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
456  
457 __END__
↑ Summary Declare/Action/CatchValidationError.pm »