Return.pm

filter: Statementstmt 72.3% 804 / 1112 Branchbran 58.1% 327 / 562 Conditioncond 46.7% 87 / 186 MC/DCmcdc 27.6% 26 / 94 Subroutinesub 86.3% 82 / 95 Podpod 83.3% 5 / 6 totaltotal 64.7% 1331 / 2055 CC 375 SCAR 41.9
CC
375
Cov
65%
__ANON__
317.3
__ANON__
171.6
VOID
145.1
CRAP 65.7
↑ Summary Return/Failure.pm »
1 package Contextual::Return;
2 31 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 31 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 31 our $VERSION = '0.004014';
5  
6 31 my %attrs_of;
7  
8 # This is localized as caller to hide the interim blocks...
9 my $smart_caller;
10  
11 # Fake out Carp::*, and Scalar::Util::blessed() very early...
12 31 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.0
13 31 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 31 my $fallback_caller = *CORE::GLOBAL::caller{CODE};
16 31 ▶ if (!defined $fallback_caller) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fallback_caller) 31 0 31
17 3313 ▶ *CORE::GLOBAL::caller = sub (;$) {
Subroutine __ANON__: called CC=5 SCAR=16.1
18 3313 my ($height) = @_;
19 3313 $height++;
20 3313 my @caller = CORE::caller($height);
21 3313 ▶ if ( CORE::caller() eq 'DB' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (caller() eq "DB") 7 3306 3313
22 # Oops, redo picking up @DB::args
23 package DB;
24 7 @caller = CORE::caller($height);
25 }
26  
27 3313 ▶ return if ! @caller; # empty
Branch: 1 branch
BranchTrueFalseTotal
unless @caller 404 2909 3313
28 2909 ▶ return $caller[0] if ! wantarray; # scalar context
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 1966 943 2909
29 943 ▶ return @_ ? @caller : @caller[0..2]; # extra info or regular
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 929 14 943
30 31 };
31 }
32 135 ▶ $smart_caller = sub (;$) {
Subroutine __ANON__: called CC=12 SCAR=27.4
33 135 ▶ my ($uplevels) = $_[0] || 0;
Condition100%2/2
$_[0] || 0
l!l
1296
MC/DC100%1/1
$_[0] || 0
$_[0]
Truth table100%2/2
A
A= $_[0]
Aresult
11
00
34 135 my @caller;
35 135 ▶ if (CORE::caller eq 'DB') {
Branch: 1 branch
BranchTrueFalseTotal
if (caller eq 'DB') { } 18 117 135
36 package DB;
37 18 ▶ if ($fallback_caller) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fallback_caller) { } 0 18 18
38 0 ▶ @caller = $fallback_caller->($uplevels + 5 + $Contextual::Return::uplevel)
Branch: 1 branch
BranchTrueFalseTotal
if $Contextual::Return::uplevel 0 0 0
39 if $Contextual::Return::uplevel;
40 0 @caller = $fallback_caller->($uplevels + 4);
41 }
42 else {
43 18 ▶ @caller = CORE::caller($uplevels + 5 + $Contextual::Return::uplevel)
Branch: 1 branch
BranchTrueFalseTotal
if $Contextual::Return::uplevel 18 0 18
44 if $Contextual::Return::uplevel;
45 18 @caller = CORE::caller($uplevels + 4);
46 }
47 }
48 else {
49 117 ▶ if ($fallback_caller) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fallback_caller) { } 0 117 117
50 0 ▶ @caller = $fallback_caller->($uplevels + 5 + $Contextual::Return::uplevel)
Branch: 1 branch
BranchTrueFalseTotal
if $Contextual::Return::uplevel 0 0 0
51 if $Contextual::Return::uplevel;
52 0 @caller = $fallback_caller->($uplevels + 4);
53 }
54 else {
55 117 ▶ @caller = CORE::caller($uplevels + 5 + $Contextual::Return::uplevel)
Branch: 1 branch
BranchTrueFalseTotal
if $Contextual::Return::uplevel 97 20 117
56 if $Contextual::Return::uplevel;
57 117 @caller = CORE::caller($uplevels + 4);
58 }
59 }
60 135 ▶ return if ! @caller; # empty
Branch: 1 branch
BranchTrueFalseTotal
unless @caller 54 81 135
61 81 ▶ return $caller[0] if ! wantarray; # scalar context
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 23 58 81
62 58 ▶ return @_ ? @caller : @caller[0..2]; # extra info or regular
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 57 1 58
63 31 };
64  
65 31 ▶ use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 31 my $real_carp = *Carp::carp{CODE};
67 31 my $real_croak = *Carp::croak{CODE};
68  
69 1 ▶ *Carp::carp = sub {
Subroutine __ANON__: called CC=2 SCAR=8.1
70 1 ▶ goto &{$real_carp} if !$Contextual::Return::uplevel;
Branch: 1 branch
BranchTrueFalseTotal
unless $Contextual::Return::uplevel 1 0 1
71 0 warn _in_context(@_);
72 31 };
73  
74 6 ▶ *Carp::croak = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
75 6 ▶ goto &{$real_croak} if !$Contextual::Return::uplevel;
Branch: 1 branch
BranchTrueFalseTotal
unless $Contextual::Return::uplevel 2 4 6
76 4 die _in_context(@_);
77 31 };
78  
79 # Scalar::Util::blessed()...
80 31 ▶ use Scalar::Util 'refaddr';
Subroutine BEGIN: called CC=1 SCAR=0.0
81  
82 # Remember the current blessed()...
83 31 my $original_blessing = *Scalar::Util::blessed{CODE};
84  
85 # ...and replace it...
86 232 ▶ *Scalar::Util::blessed = sub($) {
Subroutine __ANON__: called CC=7 SCAR=19.5
87 31 ▶ no warnings 'redefine'; local *CORE::GLOBAL::caller = $smart_caller;
Subroutine BEGIN: called CC=1 SCAR=0.0
88  
89 # Are we operating on a CRV???
90 232 ▶ my $attrs = $attrs_of{refaddr $_[0] or q{}};
Condition100%2/2
builtin::refaddr($_[0]) || ''
l!l
2311
MC/DC100%1/1
builtin::refaddr($_[0]) || ''
builtin::refaddr($_[0])
Truth table100%2/2
A
A= builtin::refaddr($_[0])
Aresult
11
00
91  
92 # If not, use the original code...
93 232 ▶ goto &{$original_blessing} if !$attrs;
Branch: 1 branch
BranchTrueFalseTotal
unless $attrs 218 14 232
94  
95 # Does this object have a BLESSED handler???
96 14 ▶ if (exists $attrs->{BLESSED}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $attrs->{"BLESSED"}) 2 12 14
97 2 return $attrs->{BLESSED}->(@{$attrs->{args}});
98 }
99  
100 # Otherwise, find the appropriate scalar handler...
101 handler:
102 12 for my $context (qw( OBJREF LAZY REF SCALAR VALUE NONVOID DEFAULT )) {
103 68 ▶ my $handler = $attrs->{$context}
Branch: 1 branch
BranchTrueFalseTotal
my $handler = $attrs->{$context} or next handler 12 56 68
104 or next handler;
105  
106 12 my $obj_ref = eval { $handler->(@{$attrs->{args}}) };
107  
108 12 my $was_blessed = $original_blessing->($obj_ref);
109 12 ▶ return $was_blessed if $was_blessed;
Branch: 1 branch
BranchTrueFalseTotal
if $was_blessed 6 6 12
110 }
111  
112 # Otherwise, simulate unblessed status...
113 6 return undef;
114 31 };
115 }
116  
117  
118  
119 40 ▶sub _in_context {
Subroutine _in_context: called CC=7 SCAR=19.5
120 40 my $msg = join q{}, @_;
121  
122 # Start looking in caller...
123 40 my $stack_frame = 1;
124 40 my ($package, $file, $line, $sub) = CORE::caller($stack_frame++);
125  
126 40 my ($orig_package, $prev_package) = ($package) x 2;
127 40 my $LOC = qq{at $file line $line};
128  
129 # Walk up stack...
130 STACK_FRAME:
131 40 while (1) {
132 141 my ($package, $file, $line, $sub) = CORE::caller($stack_frame++);
133  
134 # Fall off the top of the stack...
135 141 ▶ last STACK_FRAME if !defined $package;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $package 18 123 141
136  
137 # Ignore this module (and any helpers)...
138 123 ▶ next STACK_FRAME if $package =~ m{^Contextual::Return}xms;
Branch: 1 branch
BranchTrueFalseTotal
if $package =~ /^Contextual::Return/msx 23 100 123
139  
140 # Track the call up the stack...
141 100 $LOC = qq{at $file line $line};
142  
143 # Ignore any @CARP_NOT'ed packages
144 next STACK_FRAME
145 31 ▶ if do { no strict 'refs'; *{$package.'::CARP_NOT'}{ARRAY}; };
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if do { no strict 'refs'; *{$package . '::CARP_NOT';}{"ARRAY"} } 30 70 100
146  
147 # Ignore transitions within original caller...
148 next STACK_FRAME
149 70 ▶ if $package eq $orig_package && $prev_package eq $orig_package;
Branch: 1 branch
BranchTrueFalseTotal
if $package eq $orig_package and $prev_package eq $orig_package 48 22 70
Condition66%2/3
$package eq $orig_package and $prev_package eq $orig_package
!ll&&!rl&&r
22048
MC/DC50%1/2
$package eq $orig_package and $prev_package eq $orig_package
$package eq $orig_package $prev_package eq $orig_package
Truth table66%2/3
A and B
A= $package eq $orig_packageB= $prev_package eq $orig_package
ABresult
0X0
100
111
150  
151 # If we get a transition out of the original package, we're there...
152 22 last STACK_FRAME;
153 }
154  
155 # Insert location details...
156 40 ▶ $msg =~ s/<LOC>/$LOC/g or $msg =~ s/[^\S\n]*$/ $LOC/;
Branch: 1 branch
BranchTrueFalseTotal
$msg =~ s/<LOC>/$LOC/g or $msg =~ s/[^\S\n]*$/ $LOC/ 3 37 40
157 40 $msg =~ s/$/\n/;
158 40 return $msg;
159 }
160  
161 # Indentation corresponds to inherited fall-back relationships...
162 31 my @CONTEXTS = qw(
163 DEFAULT
164 VOID
165 NONVOID
166 LIST
167 SCALAR
168 VALUE
169 STR
170 NUM
171 BOOL
172 PUREBOOL
173 REF
174 SCALARREF
175 ARRAYREF
176 CODEREF
177 HASHREF
178 GLOBREF
179 OBJREF
180 METHOD
181 BLESSED
182 );
183  
184 31 my @ALL_EXPORTS = (
185 @CONTEXTS,
186 qw(
187 LAZY RESULT RVALUE METHOD FAIL
188 FIXED RECOVER LVALUE RETOBJ FAIL_WITH
189 ACTIVE CLEANUP NVALUE STRICT BLESSED
190 )
191 );
192  
193 31 my %STD_NAME_FOR = map { $_ => $_ } @ALL_EXPORTS;
194  
195 68 ▶sub import {
Subroutine import: called CC=8 SCAR=20.8
196 # Load utility module for failure handlers...
197 68 ▶ if (require Contextual::Return::Failure) {
Branch: 1 branch
BranchTrueFalseTotal
if (require Contextual::Return::Failure) 68 0 68
198 68 *FAIL = \&Contextual::Return::Failure::_FAIL;
199 68 *FAIL_WITH = \&Contextual::Return::Failure::_FAIL_WITH;
200 }
201  
202 # Don't need the package name...
203 68 shift @_;
204  
205 # If args, export nothing by default; otherwise export all...
206 68 ▶ my %exports = @_ ? () : %STD_NAME_FOR;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 8 60 68
207  
208 # All args are export either selectors and/or renamers...
209 68 ▶ while (my $selector = shift @_) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $selector = shift @_) 15 66 81
210 15 my $next_arg = $_[0];
211 my $renamer = (defined $next_arg
212 && !ref $next_arg
213 15 ▶ && !exists $STD_NAME_FOR{$next_arg})
Branch: 1 branch
BranchTrueFalseTotal
defined $next_arg && !ref($next_arg) && !exists $STD_NAME_FOR{$next_arg} ? : 6 9 15
Condition83%5/6
defined $next_arg and not ref $next_arg and not exists $STD_NAME_FOR{$next_arg}
!ll&&!rl&&r
636
defined $next_arg and not ref $next_arg
!ll&&!rl&&r
609
MC/DC66%2/3
defined $next_arg and not ref $next_arg and not exists $STD_NAME_FOR{$next_arg}
defined $next_arg not ref $next_arg not exists $STD_NAME_FOR{$next_arg}
Truth table75%3/4
A and not(B) and not(C)
A= defined $next_argB= not ref $next_argC= not exists $STD_NAME_FOR{$next_arg}
ABCresult
0XX0
10X0
1100
1111
214 ? shift(@_)
215 : undef;
216 15 %exports = (%exports, _add_exports_for($selector, $renamer));
217 }
218  
219 # Loop through possible exports, exporting anything requested...
220 66 my $caller = CORE::caller;
221 EXPORT:
222 66 for my $subname (keys %exports) {
223 31 ▶ no strict qw( refs );
Subroutine BEGIN: called CC=1 SCAR=0.0
224 1992 *{$caller.'::'.$exports{$subname}} = \&{$subname};
225 }
226 };
227  
228 15 ▶sub _add_exports_for {
Subroutine _add_exports_for: called CC=8 SCAR=20.9
229 15 my ($selector, $renamer) = @_;
230  
231 # If no renamer, use original name...
232 15 ▶ $renamer ||= '%s';
Condition100%2/2
$renamer ||= "%s"
l!l
69
MC/DC100%1/1
$renamer ||= "%s"
$renamer
Truth table100%2/2
A
A= $renamer
Aresult
11
00
233  
234 # Handle different types of selector...
235 15 ▶ my $selector_type = ref($selector) || 'literal';
Condition100%2/2
ref $selector || 'literal'
l!l
510
MC/DC100%1/1
ref $selector || 'literal'
ref $selector
Truth table100%2/2
A
A= ref $selector
Aresult
11
00
236  
237 # Array selector recursively export each element...
238 15 ▶ if ($selector_type eq 'ARRAY') {
Branch: 3 branches
BranchTrueFalseTotal
if ($selector_type eq 'ARRAY') { } 0 15 15
elsif ($selector_type eq 'Regexp') { } 4 11 15
elsif ($selector_type eq 'literal') { } 10 1 11
239 0 return map { _add_exports_for($_,$renamer) } @{$selector};
240 }
241 elsif ($selector_type eq 'Regexp') {
242 4 my @selected = grep {/$selector/} @ALL_EXPORTS;
243 4 ▶ if (!@selected) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@selected) 1 3 4
244 1 Carp::carp("use Contextual::Return $selector didn't export anything");
245 }
246 31 ▶ no if $] >= 5.022, warnings => 'redundant';
Subroutine BEGIN: called CC=1 SCAR=0.0
247 4 return map { $_ => sprintf($renamer, $_) } @selected;
248 }
249 elsif ($selector_type eq 'literal') {
250 Carp::croak "Can't export $selector: no such handler"
251 10 ▶ if !exists $STD_NAME_FOR{$selector};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $STD_NAME_FOR{$selector} 1 9 10
252 31 ▶ no if $] >= 5.022, warnings => 'redundant';
Subroutine BEGIN: called CC=1 SCAR=0.0
253 9 return ( $selector => sprintf($renamer, $selector) );
254 }
255 else {
256 1 Carp::croak "Can't use $selector_type as export specifier";
257 }
258 }
259  
260  
261 # Let handlers access the result object they're inside...
262  
263 1 ▶sub RETOBJ() {
Subroutine RETOBJ: called CC=1 SCAR=0.0
Pod undocumented
264 1 our $__RETOBJ__;
265 1 return $__RETOBJ__;
266 }
267  
268  
269 31 ▶use Scalar::Util qw( refaddr );
Subroutine BEGIN: called CC=1 SCAR=0.0
270  
271 # Override return value in a C::R handler...
272 40 ▶sub RESULT(;&) {
Subroutine RESULT: called CC=6 SCAR=18.0
Pod documented
273 40 my ($block) = @_;
274  
275 # Determine call context and arg list...
276 40 my $context;
277 40 my $args = do { package DB; $context=(CORE::caller 1)[5]; my $args = \@DB::args; ()=CORE::caller(1); $args };
278  
279 # No args -> return appropriate value...
280 40 ▶ if (!@_) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 1 39 40
281 0 ▶ return $context ? @{ $Contextual::Return::__RESULT__ || [] }
Branch: 1 branch
BranchTrueFalseTotal
$context ? : 0 1 1
Condition0%0/2
$Contextual::Return::__RESULT__ || []
l!l
00
MC/DC0%0/1
$Contextual::Return::__RESULT__ || []
$Contextual::Return::__RESULT__
Truth table0%0/2
A
A= $Contextual::Return::__RESULT__
Aresult
11
00
282 : $Contextual::Return::__RESULT__->[0]
283 ;
284 }
285  
286 # Hide from caller() and the enclosing eval{}...
287  
288 # Evaluate block in context and cache result...
289 39 local $Contextual::Return::uplevel = $Contextual::Return::uplevel+1;
290 31 ▶ no warnings 'redefine'; local *CORE::GLOBAL::caller = $smart_caller;
Subroutine BEGIN: called CC=1 SCAR=0.0
291 $Contextual::Return::__RESULT__
292 5 ▶ = $context ? [ $block->(@{$args}) ]
Branch: 1 branch
BranchTrueFalseTotal
defined $context ? : 33 1 34
293 33 : defined $context ? [ scalar $block->(@{$args}) ]
294 39 ▶ : do { $block->(@{$args}); [] }
Branch: 1 branch
BranchTrueFalseTotal
$context ? : 5 34 39
295 ;
296  
297 39 return;
298 }
299  
300 sub RVALUE(&;@) :lvalue;
301 sub LVALUE(&;@) :lvalue;
302 sub NVALUE(&;@) :lvalue;
303  
304 31 my %opposite_of = (
305 'RVALUE' => 'LVALUE or NVALUE',
306 'LVALUE' => 'RVALUE or NVALUE',
307 'NVALUE' => 'LVALUE or RVALUE',
308 );
309  
310  
311 31 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.3
312 31 for my $subname (qw( RVALUE LVALUE NVALUE) ) {
313 31 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
314 93 ▶ *{$subname} = sub(&;@) :lvalue { # (handler, return_lvalue);
Subroutine __ANON__: called CC=9 SCAR=23.9
315 28 my $handler = shift;
316 28 my $impl;
317 28 my $args = do{ package DB; ()=CORE::caller(1); my $args = \@DB::args; ()=CORE::caller(1); $args };
318 28 ▶ if (@_==0) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 0) { } 10 18 28
elsif (@_ == 1 and $impl = tied $_[0]) { } 18 0 18
319 10 $impl = tie $_[0], 'Contextual::Return::Lvalue',
320 $subname => $handler, args=>$args;
321 }
322 ▶ elsif (@_==1 and $impl = tied $_[0]) {
Condition33%1/3
@_ == 1 and $impl = tied $_[0]
!ll&&!rl&&r
0018
MC/DC0%0/2
@_ == 1 and $impl = tied $_[0]
@_ == 1 $impl = tied $_[0]
Truth table33%1/3
A and B
A= @_ == 1B= $impl = tied $_[0]
ABresult
0X0
100
111
323 die _in_context "Can't install two $subname handlers"
324 18 ▶ if exists $impl->{$subname};
Branch: 1 branch
BranchTrueFalseTotal
if exists $impl->{$subname} 0 18 18
325 18 $impl->{$subname} = $handler;
326 }
327 else {
328 0 ▶ my $vals = join q{, }, map { tied $_ ? keys %{tied $_}
Branch: 2 branches
BranchTrueFalseTotal
tied $_ ? : 0 0 0
defined $_ ? : 0 0 0
329 : defined $_ ? $_
330 : 'undef'
331 } @_;
332 0 die _in_context "Expected a $opposite_of{$subname} block ",
333 "after the $subname block <LOC> ",
334 "but found instead: $vals\n";
335 }
336  
337 # Handle void context calls...
338 28 ▶ if (!defined wantarray && $impl->{NVALUE}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined wantarray and $impl->{"NVALUE"}) 1 27 28
Condition66%2/3
not defined wantarray and $impl->{"NVALUE"}
!ll&&!rl&&r
2701
MC/DC50%1/2
not defined wantarray and $impl->{"NVALUE"}
not defined wantarray $impl->{"NVALUE"}
Truth table66%2/3
not(A) and B
A= not defined wantarrayB= $impl->{"NVALUE"}
ABresult
0X0
100
111
339 # Fake out caller() and Carp...
340 1 local $Contextual::Return::uplevel = 1;
341 31 ▶ no warnings 'redefine'; local *CORE::GLOBAL::caller = $smart_caller;
Subroutine BEGIN: called CC=1 SCAR=0.0
342  
343 # Call and clear handler...
344 1 local $Contextual::Return::__RETOBJ__ = $impl;
345 1 $impl->{NVALUE}( @{$impl->{args}} );
346 1 delete $impl->{NVALUE};
347 }
348 28 $_[0];
349 }
350 93 }
351 }
352  
353 31 for my $modifier_name (qw< STRICT FIXED ACTIVE >) {
354 31 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
355 93 ▶ *{$modifier_name} = sub ($) {
Subroutine __ANON__: called CC=33 SCAR=57.6
356 21 my ($crv) = @_;
357 21 ▶ my $attrs = $attrs_of{refaddr $crv or q{}};
Condition50%1/2
builtin::refaddr($crv) || ''
l!l
210
MC/DC0%0/1
builtin::refaddr($crv) || ''
builtin::refaddr($crv)
Truth table50%1/2
A
A= builtin::refaddr($crv)
Aresult
11
00
358  
359 # Track context...
360 21 my $wantarray = wantarray;
361 31 ▶ use Want;
Subroutine BEGIN: called CC=1 SCAR=0.0
362 21 ▶ $attrs->{want_pure_bool} ||= Want::want('BOOL');
Condition66%2/3
$attrs->{"want_pure_bool"} ||= Want::want("BOOL")
l!l&&r!l&&!r
0120
MC/DC50%1/2
$attrs->{"want_pure_bool"} ||= Want::want("BOOL")
$attrs->{"want_pure_bool"} Want::want("BOOL")
Truth table66%2/3
A ||= B
A= $attrs->{"want_pure_bool"}B= Want::want("BOOL")
ABresult
1X1
011
000
363  
364 # Remember the modification...
365 21 $attrs->{$modifier_name} = 1;
366  
367 # Prepare for exception handling...
368 21 my $recover = $attrs->{RECOVER};
369 21 local $Contextual::Return::uplevel = 2;
370 31 ▶ no warnings 'redefine'; local *CORE::GLOBAL::caller = $smart_caller;
Subroutine BEGIN: called CC=1 SCAR=0.0
371  
372 # Handle list context directly, if possible...
373 21 ▶ if ($wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wantarray) 2 19 21
374 2 local $Contextual::Return::__RESULT__;
375 # List or ancestral handlers...
376 handler:
377 2 for my $context (qw(LIST VALUE NONVOID DEFAULT)) {
378 my $handler = $attrs->{$context}
379 or $attrs->{STRICT} and last handler
380 2 ▶ or next handler;
Branch: 1 branch
BranchTrueFalseTotal
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler or next handler 2 0 2
Condition20%1/5
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
l!l&&r!l&&!r
200
$attrs->{"STRICT"} and last handler
!ll
00
MC/DC0%0/2
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
my $handler = $attrs->{$context} $attrs->{"STRICT"}
Truth table33%1/3
A or B
A= my $handler = $attrs->{$context}B= $attrs->{"STRICT"}
ABresult
1X1
011
000
381  
382 2 my @rv = eval { $handler->(@{$attrs->{args}}) };
383 2 ▶ if ($recover) {
Branch: 2 branches
BranchTrueFalseTotal
if ($recover) { } 0 2 2
elsif ($@) { } 0 2 2
384 0 ▶ if (!$Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Contextual::Return::__RESULT__) 0 0 0
385 0 $Contextual::Return::__RESULT__ = [@rv];
386 }
387 0 () = $recover->(@{$attrs->{args}});
388 }
389 elsif ($@) {
390 0 die $@;
391 }
392  
393 2 ▶ return @rv if !$Contextual::Return::__RESULT__;
Branch: 1 branch
BranchTrueFalseTotal
unless $Contextual::Return::__RESULT__ 2 0 2
394 0 return @{$Contextual::Return::__RESULT__};
395 }
396 # Convert to list from arrayref handler...
397 0 ▶ if (!$attrs->{STRICT} and my $handler = $attrs->{ARRAYREF}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $attrs->{"STRICT"} and my $handler = $attrs->{"ARRAYREF"}) 0 0 0
Condition0%0/3
not $attrs->{"STRICT"} and my $handler = $attrs->{"ARRAYREF"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $attrs->{"STRICT"} and my $handler = $attrs->{"ARRAYREF"}
not $attrs->{"STRICT"} my $handler = $attrs->{"ARRAYREF"}
Truth table0%0/3
not(A) and B
A= not $attrs->{"STRICT"}B= my $handler = $attrs->{"ARRAYREF"}
ABresult
0X0
100
111
398 0 my $array_ref = eval { $handler->(@{$attrs->{args}}) };
399  
400 0 ▶ if ($recover) {
Branch: 2 branches
BranchTrueFalseTotal
if ($recover) { } 0 0 0
elsif ($@) { } 0 0 0
401 0 ▶ if (!$Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Contextual::Return::__RESULT__) 0 0 0
402 0 $Contextual::Return::__RESULT__ = [$array_ref];
403 }
404 0 scalar $recover->(@{$attrs->{args}});
405 }
406 elsif ($@) {
407 0 die $@;
408 }
409  
410 # Array ref may be returned directly, or via RESULT{}...
411 0 ▶ $array_ref = $Contextual::Return::__RESULT__->[0]
Branch: 1 branch
BranchTrueFalseTotal
if $Contextual::Return::__RESULT__ 0 0 0
412 if $Contextual::Return::__RESULT__;
413  
414 0 ▶ return @{$array_ref} if (ref $array_ref||q{}) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if (ref $array_ref || "") eq "ARRAY" 0 0 0
Condition0%0/2
ref $array_ref || ''
l!l
00
MC/DC0%0/1
ref $array_ref || ''
ref $array_ref
Truth table0%0/2
A
A= ref $array_ref
Aresult
11
00
415 }
416 # Return scalar object as one-elem list, if possible...
417 handler:
418 0 for my $context (qw(BOOL STR NUM VALUE SCALAR LAZY)) {
419 0 ▶ last handler if $attrs->{STRICT};
Branch: 1 branch
BranchTrueFalseTotal
if $attrs->{"STRICT"} 0 0 0
420 0 ▶ return $crv if exists $attrs->{$context};
Branch: 1 branch
BranchTrueFalseTotal
if exists $attrs->{$context} 0 0 0
421 }
422 0 $@ = _in_context "Can't call $attrs->{sub} in a list context";
423 0 ▶ if ($recover) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recover) { } 0 0 0
424 0 () = $recover->(@{$attrs->{args}});
425 }
426 else {
427 0 die $@;
428 }
429 }
430  
431 # Handle void context directly...
432 19 ▶ if (!defined $wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $wantarray) 1 18 19
433 handler:
434 1 for my $context (qw< VOID DEFAULT >) {
435 my $handler = $attrs->{$context}
436 or $attrs->{STRICT} and last handler
437 1 ▶ or next handler;
Branch: 1 branch
BranchTrueFalseTotal
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler or next handler 0 0 0
Condition40%2/5
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
l!l&&r!l&&!r
001
$attrs->{"STRICT"} and last handler
!ll
01
MC/DC0%0/2
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
my $handler = $attrs->{$context} $attrs->{"STRICT"}
Truth table33%1/3
A or B
A= my $handler = $attrs->{$context}B= $attrs->{"STRICT"}
ABresult
1X1
011
000
438  
439 0 eval { $attrs->{$context}->(@{$attrs->{args}}) };
440 0 ▶ if ($recover) {
Branch: 2 branches
BranchTrueFalseTotal
if ($recover) { } 0 0 0
elsif ($@) { } 0 0 0
441 0 $recover->(@{$attrs->{args}});
442 }
443 elsif ($@) {
444 0 die $@;
445 }
446 0 last handler;
447 }
448 1 ▶ if ($attrs->{STRICT}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrs->{"STRICT"}) 1 0 1
449 1 $@ = _in_context "Can't call $attrs->{sub} in a void context";
450 1 ▶ if ($recover) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recover) { } 0 1 1
451 0 () = $recover->(@{$attrs->{args}});
452 }
453 else {
454 1 die $@;
455 }
456 }
457 0 return;
458 }
459  
460 # Otherwise, let someone else handle it...
461 18 return $crv;
462 }
463 93 }
464  
465 144 ▶sub LIST (;&$) {
Subroutine LIST: called CC=20 SCAR=42.1
Pod documented
466 144 my ($block, $crv) = @_;
467  
468 # Handle simple context tests...
469 144 ▶ return !!(CORE::caller 1)[5] if !@_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 2 142 144
470  
471 # Ensure we have an object...
472 142 my $attrs;
473 142 ▶ if (!refaddr $crv) {
Branch: 1 branch
BranchTrueFalseTotal
if (not builtin::refaddr($crv)) { } 12 130 142
474 12 my $args = do{ package DB; ()=CORE::caller(1); my $args = \@DB::args; ()=CORE::caller(1); $args };
475 12 my $subname = (CORE::caller(1))[3];
476 12 ▶ if (!defined $subname) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $subname) 0 12 12
477 0 $subname = 'bare LIST {...}';
478 }
479 12 $crv = bless \my $scalar, 'Contextual::Return::Value';
480 12 $attrs = $attrs_of{refaddr $crv} = { args => $args, sub => $subname };
481 }
482 else {
483 130 $attrs = $attrs_of{refaddr $crv};
484 }
485 142 local $Contextual::Return::__RETOBJ__ = $crv;
486  
487 # Handle repetitions...
488 die _in_context "Can't install two LIST handlers"
489 142 ▶ if exists $attrs->{LIST};
Branch: 1 branch
BranchTrueFalseTotal
if exists $attrs->{"LIST"} 1 141 142
490  
491 # Identify contexts...
492 141 my $wantarray = wantarray;
493 31 ▶ use Want;
Subroutine BEGIN: called CC=1 SCAR=0.0
494 141 ▶ $attrs->{want_pure_bool} ||= Want::want('BOOL');
Condition33%1/3
$attrs->{"want_pure_bool"} ||= Want::want("BOOL")
l!l&&r!l&&!r
00141
MC/DC0%0/2
$attrs->{"want_pure_bool"} ||= Want::want("BOOL")
$attrs->{"want_pure_bool"} Want::want("BOOL")
Truth table33%1/3
A ||= B
A= $attrs->{"want_pure_bool"}B= Want::want("BOOL")
ABresult
1X1
011
000
495  
496 # Prepare for exception handling...
497 141 my $recover = $attrs->{RECOVER};
498 141 local $Contextual::Return::uplevel = 2;
499 31 ▶ no warnings 'redefine'; local *CORE::GLOBAL::caller = $smart_caller;
Subroutine BEGIN: called CC=1 SCAR=0.0
500  
501 # Handle list context directly...
502 141 ▶ if ($wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wantarray) 2 139 141
503 2 local $Contextual::Return::__RESULT__;
504  
505 2 my @rv = eval { $block->(@{$attrs->{args}}) };
506 2 ▶ if ($recover) {
Branch: 2 branches
BranchTrueFalseTotal
if ($recover) { } 0 2 2
elsif ($@) { } 0 2 2
507 0 ▶ if (!$Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Contextual::Return::__RESULT__) 0 0 0
508 0 $Contextual::Return::__RESULT__ = [@rv];
509 }
510 0 () = $recover->(@{$attrs->{args}});
511 }
512 elsif ($@) {
513 0 die $@;
514 }
515  
516 2 ▶ return @rv if !$Contextual::Return::__RESULT__;
Branch: 1 branch
BranchTrueFalseTotal
unless $Contextual::Return::__RESULT__ 2 0 2
517 0 return @{$Contextual::Return::__RESULT__};
518 }
519  
520 # Handle void context directly...
521 139 ▶ if (!defined $wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $wantarray) 0 139 139
522 handler:
523 0 for my $context (qw< VOID DEFAULT >) {
524 my $handler = $attrs->{$context}
525 or $attrs->{STRICT} and last handler
526 0 ▶ or next handler;
Branch: 1 branch
BranchTrueFalseTotal
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler or next handler 0 0 0
Condition0%0/5
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
l!l&&r!l&&!r
000
$attrs->{"STRICT"} and last handler
!ll
00
MC/DC0%0/2
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
my $handler = $attrs->{$context} $attrs->{"STRICT"}
Truth table0%0/3
A or B
A= my $handler = $attrs->{$context}B= $attrs->{"STRICT"}
ABresult
1X1
011
000
527  
528 0 eval { $attrs->{$context}->(@{$attrs->{args}}) };
529 0 ▶ if ($recover) {
Branch: 2 branches
BranchTrueFalseTotal
if ($recover) { } 0 0 0
elsif ($@) { } 0 0 0
530 0 $recover->(@{$attrs->{args}});
531 }
532 elsif ($@) {
533 0 die $@;
534 }
535 0 last handler;
536 }
537 0 ▶ if ($attrs->{STRICT}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrs->{"STRICT"}) 0 0 0
538 0 $@ = _in_context "Can't call $attrs->{sub} in a void context";
539 0 ▶ if ($recover) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recover) { } 0 0 0
540 0 () = $recover->(@{$attrs->{args}});
541 }
542 else {
543 0 die $@;
544 }
545 }
546 0 return;
547 }
548  
549 # Otherwise, cache handler...
550 139 $attrs->{LIST} = $block;
551 139 return $crv;
552 }
553  
554  
555 62 ▶sub VOID (;&$) {
Subroutine VOID: called CC=30 SCAR=49.8
Pod documented
556 62 my ($block, $crv) = @_;
557  
558 # Handle simple context tests...
559 62 ▶ return !defined( (CORE::caller 1)[5] ) if !@_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 6 56 62
560  
561 # Ensure we have an object...
562 56 my $attrs;
563 56 ▶ if (!refaddr $crv) {
Branch: 1 branch
BranchTrueFalseTotal
if (not builtin::refaddr($crv)) { } 6 50 56
564 6 my $args = do{ package DB; ()=CORE::caller(1); my $args = \@DB::args; ()=CORE::caller(1); $args };
565 6 my $subname = (CORE::caller(1))[3];
566 6 ▶ if (!defined $subname) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $subname) 0 6 6
567 0 $subname = 'bare VOID {...}';
568 }
569 6 $crv = bless \my $scalar, 'Contextual::Return::Value';
570 6 $attrs = $attrs_of{refaddr $crv} = { args => $args, sub => $subname };
571 }
572 else {
573 50 $attrs = $attrs_of{refaddr $crv};
574 }
575 56 local $Contextual::Return::__RETOBJ__ = $crv;
576  
577 # Handle repetitions...
578 die _in_context "Can't install two VOID handlers"
579 56 ▶ if exists $attrs->{VOID};
Branch: 1 branch
BranchTrueFalseTotal
if exists $attrs->{"VOID"} 0 56 56
580  
581 # Identify contexts...
582 56 my $wantarray = wantarray;
583 31 ▶ use Want;
Subroutine BEGIN: called CC=1 SCAR=0.0
584 56 ▶ $attrs->{want_pure_bool} ||= Want::want('BOOL');
Condition66%2/3
$attrs->{"want_pure_bool"} ||= Want::want("BOOL")
l!l&&r!l&&!r
0650
MC/DC50%1/2
$attrs->{"want_pure_bool"} ||= Want::want("BOOL")
$attrs->{"want_pure_bool"} Want::want("BOOL")
Truth table66%2/3
A ||= B
A= $attrs->{"want_pure_bool"}B= Want::want("BOOL")
ABresult
1X1
011
000
585  
586 # Prepare for exception handling...
587 56 my $recover = $attrs->{RECOVER};
588 56 local $Contextual::Return::uplevel = 2;
589 31 ▶ no warnings 'redefine'; local *CORE::GLOBAL::caller = $smart_caller;
Subroutine BEGIN: called CC=1 SCAR=0.0
590  
591 # Handle list context directly, if possible...
592 56 ▶ if ($wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wantarray) 6 50 56
593 6 local $Contextual::Return::__RESULT__;
594 # List or ancestral handlers...
595 handler:
596 6 for my $context (qw(LIST VALUE NONVOID DEFAULT)) {
597 my $handler = $attrs->{$context}
598 or $attrs->{STRICT} and last handler
599 6 ▶ or next handler;
Branch: 1 branch
BranchTrueFalseTotal
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler or next handler 6 0 6
Condition20%1/5
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
l!l&&r!l&&!r
600
$attrs->{"STRICT"} and last handler
!ll
00
MC/DC0%0/2
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
my $handler = $attrs->{$context} $attrs->{"STRICT"}
Truth table33%1/3
A or B
A= my $handler = $attrs->{$context}B= $attrs->{"STRICT"}
ABresult
1X1
011
000
600  
601 6 my @rv = eval { $handler->(@{$attrs->{args}}) };
602 6 ▶ if ($recover) {
Branch: 2 branches
BranchTrueFalseTotal
if ($recover) { } 0 6 6
elsif ($@) { } 0 6 6
603 0 ▶ if (!$Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Contextual::Return::__RESULT__) 0 0 0
604 0 $Contextual::Return::__RESULT__ = [@rv];
605 }
606 0 () = $recover->(@{$attrs->{args}});
607 }
608 elsif ($@) {
609 0 die $@;
610 }
611  
612 6 ▶ return @rv if !$Contextual::Return::__RESULT__;
Branch: 1 branch
BranchTrueFalseTotal
unless $Contextual::Return::__RESULT__ 3 3 6
613 3 return @{$Contextual::Return::__RESULT__};
614 }
615 # Convert to list from arrayref handler...
616 0 ▶ if (!$attrs->{STRICT} and my $handler = $attrs->{ARRAYREF}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $attrs->{"STRICT"} and my $handler = $attrs->{"ARRAYREF"}) 0 0 0
Condition0%0/3
not $attrs->{"STRICT"} and my $handler = $attrs->{"ARRAYREF"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $attrs->{"STRICT"} and my $handler = $attrs->{"ARRAYREF"}
not $attrs->{"STRICT"} my $handler = $attrs->{"ARRAYREF"}
Truth table0%0/3
not(A) and B
A= not $attrs->{"STRICT"}B= my $handler = $attrs->{"ARRAYREF"}
ABresult
0X0
100
111
617 0 my $array_ref = eval { $handler->(@{$attrs->{args}}) };
618  
619 0 ▶ if ($recover) {
Branch: 2 branches
BranchTrueFalseTotal
if ($recover) { } 0 0 0
elsif ($@) { } 0 0 0
620 0 ▶ if (!$Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Contextual::Return::__RESULT__) 0 0 0
621 0 $Contextual::Return::__RESULT__ = [$array_ref];
622 }
623 0 scalar $recover->(@{$attrs->{args}});
624 }
625 elsif ($@) {
626 0 die $@;
627 }
628  
629 # Array ref may be returned directly, or via RESULT{}...
630 0 ▶ $array_ref = $Contextual::Return::__RESULT__->[0]
Branch: 1 branch
BranchTrueFalseTotal
if $Contextual::Return::__RESULT__ 0 0 0
631 if $Contextual::Return::__RESULT__;
632  
633 0 ▶ return @{$array_ref} if (ref $array_ref||q{}) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if (ref $array_ref || "") eq "ARRAY" 0 0 0
Condition0%0/2
ref $array_ref || ''
l!l
00
MC/DC0%0/1
ref $array_ref || ''
ref $array_ref
Truth table0%0/2
A
A= ref $array_ref
Aresult
11
00
634 }
635 # Return scalar object as one-elem list, if possible...
636 handler:
637 0 for my $context (qw(BOOL STR NUM VALUE SCALAR LAZY)) {
638 0 ▶ last handler if $attrs->{STRICT};
Branch: 1 branch
BranchTrueFalseTotal
if $attrs->{"STRICT"} 0 0 0
639 0 ▶ return $crv if exists $attrs->{$context};
Branch: 1 branch
BranchTrueFalseTotal
if exists $attrs->{$context} 0 0 0
640 }
641 0 $@ = _in_context "Can't call $attrs->{sub} in a list context";
642 0 ▶ if ($recover) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recover) { } 0 0 0
643 0 () = $recover->(@{$attrs->{args}});
644 }
645 else {
646 0 die $@;
647 }
648 }
649  
650 # Handle void context directly...
651 50 ▶ if (!defined $wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $wantarray) 2 48 50
652 2 eval { $block->(@{$attrs->{args}}) };
653  
654 2 ▶ if ($recover) {
Branch: 2 branches
BranchTrueFalseTotal
if ($recover) { } 0 2 2
elsif ($@) { } 0 2 2
655 0 $recover->(@{$attrs->{args}});
656 }
657 elsif ($@) {
658 0 die $@;
659 }
660  
661 2 return;
662 }
663  
664 # Otherwise, cache handler...
665 48 $attrs->{VOID} = $block;
666 48 return $crv;
667 }
668  
669 31 for my $context (qw( SCALAR NONVOID )) {
670 31 ▶ no strict qw( refs );
Subroutine BEGIN: called CC=1 SCAR=0.0
671 62 ▶ *{$context} = sub (;&$) {
Subroutine __ANON__: called CC=37 SCAR=51.5
672 138 my ($block, $crv) = @_;
673  
674 # Handle simple context tests...
675 138 ▶ if (!@_) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 3 135 138
676 3 my $callers_context = (CORE::caller 1)[5];
677 3 ▶ return defined $callers_context
Condition50%3/6
defined $callers_context && ($context eq 'NONVOID' || !$callers_context)
!ll&&!rl&&r
003
$context eq "NONVOID" or not $callers_context
l!l&&r!l&&!r
210
MC/DC0%0/3
defined $callers_context && ($context eq 'NONVOID' || !$callers_context)
defined $callers_context $context eq "NONVOID" not $callers_context
Truth table50%2/4
A && B or not(C)
A= defined $callers_contextB= $context eq "NONVOID"C= not $callers_context
ABCresult
0XX0
1000
11X1
1011
678 && ($context eq 'NONVOID' || !$callers_context);
679 }
680  
681 # Ensure we have an object...
682 135 my $attrs;
683 135 ▶ if (!refaddr $crv) {
Branch: 1 branch
BranchTrueFalseTotal
if (not builtin::refaddr($crv)) { } 11 124 135
684 11 my $args = do{ package DB; ()=CORE::caller(1); my $args = \@DB::args; ()=CORE::caller(1); $args };
685 11 my $subname = (CORE::caller(1))[3];
686 11 ▶ if (!defined $subname) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $subname) 0 11 11
687 0 $subname = "bare $context {...}";
688 }
689 11 $crv = bless \my $scalar, 'Contextual::Return::Value';
690 11 $attrs = $attrs_of{refaddr $crv}
691 = { args => $args, sub => $subname };
692 }
693 else {
694 124 $attrs = $attrs_of{refaddr $crv};
695 }
696 135 local $Contextual::Return::__RETOBJ__ = $crv;
697  
698 # Make sure this block is a possibility too...
699 die _in_context "Can't install two $context handlers"
700 135 ▶ if exists $attrs->{$context};
Branch: 1 branch
BranchTrueFalseTotal
if exists $attrs->{$context} 0 135 135
701 135 $attrs->{$context} = $block;
702  
703 # Identify contexts...
704 135 my $wantarray = wantarray;
705 31 ▶ use Want ();
Subroutine BEGIN: called CC=1 SCAR=0.0
706 135 ▶ $attrs->{want_pure_bool} ||= Want::want('BOOL');
Condition33%1/3
$attrs->{"want_pure_bool"} ||= Want::want("BOOL")
l!l&&r!l&&!r
00135
MC/DC0%0/2
$attrs->{"want_pure_bool"} ||= Want::want("BOOL")
$attrs->{"want_pure_bool"} Want::want("BOOL")
Truth table33%1/3
A ||= B
A= $attrs->{"want_pure_bool"}B= Want::want("BOOL")
ABresult
1X1
011
000
707  
708 # Prepare for exception handling...
709 135 my $recover = $attrs->{RECOVER};
710 135 local $Contextual::Return::uplevel = 2;
711 31 ▶ no warnings 'redefine'; local *CORE::GLOBAL::caller = $smart_caller;
Subroutine BEGIN: called CC=1 SCAR=0.0
712  
713 # Handle list context directly, if possible...
714 135 ▶ if ($wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wantarray) 2 133 135
715 2 local $Contextual::Return::__RESULT__;
716  
717 # List or ancestral handlers...
718 handler:
719 2 for my $context (qw(LIST VALUE NONVOID DEFAULT)) {
720 my $handler = $attrs->{$context}
721 or $attrs->{STRICT} and last handler
722 7 ▶ or next handler;
Branch: 1 branch
BranchTrueFalseTotal
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler or next handler 1 6 7
Condition60%3/5
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
l!l&&r!l&&!r
106
$attrs->{"STRICT"} and last handler
!ll
60
MC/DC50%1/2
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
my $handler = $attrs->{$context} $attrs->{"STRICT"}
Truth table66%2/3
A or B
A= my $handler = $attrs->{$context}B= $attrs->{"STRICT"}
ABresult
1X1
011
000
723  
724 1 my @rv = eval { $handler->(@{$attrs->{args}}) };
725 1 ▶ if ($recover) {
Branch: 2 branches
BranchTrueFalseTotal
if ($recover) { } 0 1 1
elsif ($@) { } 0 1 1
726 0 ▶ if (!$Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Contextual::Return::__RESULT__) 0 0 0
727 0 $Contextual::Return::__RESULT__ = [@rv];
728 }
729 0 () = $recover->(@{$attrs->{args}});
730 }
731 elsif ($@) {
732 0 die $@;
733 }
734  
735 1 ▶ return @rv if !$Contextual::Return::__RESULT__;
Branch: 1 branch
BranchTrueFalseTotal
unless $Contextual::Return::__RESULT__ 1 0 1
736 0 return @{$Contextual::Return::__RESULT__};
737 }
738 # Convert to list from arrayref handler...
739 1 ▶ if (!$attrs->{STRICT} and my $handler = $attrs->{ARRAYREF}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $attrs->{"STRICT"} and my $handler = $attrs->{"ARRAYREF"}) 0 1 1
Condition33%1/3
not $attrs->{"STRICT"} and my $handler = $attrs->{"ARRAYREF"}
!ll&&!rl&&r
010
MC/DC0%0/2
not $attrs->{"STRICT"} and my $handler = $attrs->{"ARRAYREF"}
not $attrs->{"STRICT"} my $handler = $attrs->{"ARRAYREF"}
Truth table33%1/3
not(A) and B
A= not $attrs->{"STRICT"}B= my $handler = $attrs->{"ARRAYREF"}
ABresult
0X0
100
111
740  
741 0 my $array_ref = eval { $handler->(@{$attrs->{args}}) };
742 0 ▶ if ($recover) {
Branch: 2 branches
BranchTrueFalseTotal
if ($recover) { } 0 0 0
elsif ($@) { } 0 0 0
743 0 ▶ if (!$Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Contextual::Return::__RESULT__) 0 0 0
744 0 $Contextual::Return::__RESULT__ = [$array_ref];
745 }
746 0 scalar $recover->(@{$attrs->{args}});
747 }
748 elsif ($@) {
749 0 die $@;
750 }
751  
752 # Array ref may be returned directly, or via RESULT{}...
753 0 ▶ $array_ref = $Contextual::Return::__RESULT__->[0]
Branch: 1 branch
BranchTrueFalseTotal
if $Contextual::Return::__RESULT__ 0 0 0
754 if $Contextual::Return::__RESULT__;
755  
756 0 ▶ return @{$array_ref} if (ref $array_ref||q{}) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if (ref $array_ref || "") eq "ARRAY" 0 0 0
Condition0%0/2
ref $array_ref || ''
l!l
00
MC/DC0%0/1
ref $array_ref || ''
ref $array_ref
Truth table0%0/2
A
A= ref $array_ref
Aresult
11
00
757 }
758 # Return scalar object as one-elem list, if possible...
759 handler:
760 1 for my $context (qw(BOOL STR NUM VALUE SCALAR LAZY)) {
761 5 ▶ last if $attrs->{STRICT};
Branch: 1 branch
BranchTrueFalseTotal
if $attrs->{"STRICT"} 0 5 5
762 5 ▶ return $crv if exists $attrs->{$context};
Branch: 1 branch
BranchTrueFalseTotal
if exists $attrs->{$context} 1 4 5
763 }
764 0 die _in_context "Can't call $attrs->{sub} in a list context";
765 }
766  
767 # Handle void context directly...
768 133 ▶ if (!defined $wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $wantarray) 1 132 133
769 handler:
770 1 for my $context (qw< VOID DEFAULT >) {
771 my $handler = $attrs->{$context}
772 or $attrs->{STRICT} and last handler
773 1 ▶ or next handler;
Branch: 1 branch
BranchTrueFalseTotal
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler or next handler 1 0 1
Condition20%1/5
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
l!l&&r!l&&!r
100
$attrs->{"STRICT"} and last handler
!ll
00
MC/DC0%0/2
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
my $handler = $attrs->{$context} $attrs->{"STRICT"}
Truth table33%1/3
A or B
A= my $handler = $attrs->{$context}B= $attrs->{"STRICT"}
ABresult
1X1
011
000
774  
775 1 eval { $handler->(@{$attrs->{args}}) };
776 1 ▶ if ($recover) {
Branch: 2 branches
BranchTrueFalseTotal
if ($recover) { } 0 1 1
elsif ($@) { } 1 0 1
777 0 $recover->(@{$attrs->{args}});
778 }
779 elsif ($@) {
780 1 die $@;
781 }
782  
783 0 last handler;
784 }
785 0 ▶ if ($attrs->{STRICT}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrs->{"STRICT"}) 0 0 0
786 0 $@ = _in_context "Can't call $attrs->{sub} in a void context";
787 0 ▶ if ($recover) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recover) { } 0 0 0
788 0 () = $recover->(@{$attrs->{args}});
789 }
790 else {
791 0 die $@;
792 }
793 }
794 0 return;
795 }
796  
797 # Otherwise, defer evaluation by returning an object...
798 132 return $crv;
799 }
800 62 }
801  
802 handler:
803 31 for my $context_name (@CONTEXTS, qw< RECOVER _internal_LIST CLEANUP >) {
804 682 ▶ next handler if $context_name eq 'LIST' # These
Branch: 1 branch
BranchTrueFalseTotal
if $context_name eq "LIST" or $context_name eq "VOID" or $context_name eq "SCALAR" or $context_name eq "NONVOID" 124 558 682
Condition100%9/9
$context_name eq "LIST" or $context_name eq "VOID" or $context_name eq "SCALAR" or $context_name eq "NONVOID"
l!l&&r!l&&!r
9331558
$context_name eq "LIST" or $context_name eq "VOID" or $context_name eq "SCALAR"
l!l&&r!l&&!r
6231589
$context_name eq "LIST" or $context_name eq "VOID"
l!l&&r!l&&!r
3131620
MC/DC100%4/4
$context_name eq "LIST" or $context_name eq "VOID" or $context_name eq "SCALAR" or $context_name eq "NONVOID"
$context_name eq "LIST" $context_name eq "VOID" $context_name eq "SCALAR" $context_name eq "NONVOID"
Truth table100%5/5
A or B or C or D
A= $context_name eq "LIST"B= $context_name eq "VOID"C= $context_name eq "SCALAR"D= $context_name eq "NONVOID"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
805 || $context_name eq 'VOID' # four
806 || $context_name eq 'SCALAR' # handled
807 || $context_name eq 'NONVOID'; # separately
808  
809 31 ▶ no strict qw( refs );
Subroutine BEGIN: called CC=1 SCAR=0.0
810 558 ▶ *{$context_name} = sub (&;$) {
Subroutine __ANON__: called CC=36 SCAR=40.3
811 1119 my ($block, $crv) = @_;
812  
813 # Ensure we have an object...
814 1119 my $attrs;
815 1119 ▶ if (!refaddr $crv) {
Branch: 1 branch
BranchTrueFalseTotal
if (not builtin::refaddr($crv)) { } 217 902 1119
816 217 my $args = do{ package DB; ()=CORE::caller(1); my $args = \@DB::args; ()=CORE::caller(1); $args };
817 217 my $subname = (CORE::caller(1))[3];
818 217 ▶ if (!defined $subname) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $subname) 0 217 217
819 0 $subname = "bare $context_name {...}";
820 }
821 217 $crv = bless \my $scalar, 'Contextual::Return::Value';
822 217 $attrs = $attrs_of{refaddr $crv}
823 = { args => $args, sub => $subname };
824 }
825 else {
826 902 $attrs = $attrs_of{refaddr $crv};
827 }
828 1119 local $Contextual::Return::__RETOBJ__ = $crv;
829  
830 # Make sure this block is a possibility too...
831 1119 ▶ if ($context_name ne '_internal_LIST') {
Branch: 1 branch
BranchTrueFalseTotal
if ($context_name ne "_internal_LIST") 1119 0 1119
832 die _in_context "Can't install two $context_name handlers"
833 1119 ▶ if exists $attrs->{$context_name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $attrs->{$context_name} 0 1119 1119
834 1119 $attrs->{$context_name} = $block;
835 }
836  
837 # Identify contexts...
838 1119 my $wantarray = wantarray;
839 31 ▶ use Want ();
Subroutine BEGIN: called CC=1 SCAR=0.0
840 1119 ▶ $attrs->{want_pure_bool} ||= Want::want('BOOL');
Condition66%2/3
$attrs->{"want_pure_bool"} ||= Want::want("BOOL")
l!l&&r!l&&!r
0121107
MC/DC50%1/2
$attrs->{"want_pure_bool"} ||= Want::want("BOOL")
$attrs->{"want_pure_bool"} Want::want("BOOL")
Truth table66%2/3
A ||= B
A= $attrs->{"want_pure_bool"}B= Want::want("BOOL")
ABresult
1X1
011
000
841  
842 # Prepare for exception handling...
843 1119 my $recover = $attrs->{RECOVER};
844 1119 local $Contextual::Return::uplevel = 2;
845 31 ▶ no warnings 'redefine'; local *CORE::GLOBAL::caller = $smart_caller;
Subroutine BEGIN: called CC=1 SCAR=0.0
846  
847 # Handle list context directly, if possible...
848 1119 ▶ if ($wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wantarray) 15 1104 1119
849 15 ▶ local $Contextual::Return::__RESULT__
Branch: 1 branch
BranchTrueFalseTotal
$context_name eq 'RECOVER' ? : 0 15 15
850 = $context_name eq 'RECOVER' ? $Contextual::Return::__RESULT__
851 : undef
852 ;
853  
854 # List or ancestral handlers...
855 handler:
856 15 for my $context (qw(LIST VALUE NONVOID DEFAULT)) {
857 my $handler = $attrs->{$context}
858 or $attrs->{STRICT} and last handler
859 36 ▶ or next handler;
Branch: 1 branch
BranchTrueFalseTotal
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler or next handler 12 24 36
Condition60%3/5
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
l!l&&r!l&&!r
12024
$attrs->{"STRICT"} and last handler
!ll
240
MC/DC50%1/2
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
my $handler = $attrs->{$context} $attrs->{"STRICT"}
Truth table66%2/3
A or B
A= my $handler = $attrs->{$context}B= $attrs->{"STRICT"}
ABresult
1X1
011
000
860  
861 12 my @rv = eval { $handler->(@{$attrs->{args}}) };
862 12 ▶ if ($recover) {
Branch: 2 branches
BranchTrueFalseTotal
if ($recover) { } 2 10 12
elsif ($@) { } 3 7 10
863 2 ▶ if (!$Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Contextual::Return::__RESULT__) 2 0 2
864 2 $Contextual::Return::__RESULT__ = [@rv];
865 }
866 2 () = $recover->(@{$attrs->{args}});
867 }
868 elsif ($@) {
869 3 die $@;
870 }
871  
872 9 ▶ return @rv if !$Contextual::Return::__RESULT__;
Branch: 1 branch
BranchTrueFalseTotal
unless $Contextual::Return::__RESULT__ 6 3 9
873 3 return @{$Contextual::Return::__RESULT__};
874 }
875 # Convert to list from arrayref handler...
876 3 ▶ if (!$attrs->{STRICT} and my $handler = $attrs->{ARRAYREF}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $attrs->{"STRICT"} and my $handler = $attrs->{"ARRAYREF"}) 1 2 3
Condition66%2/3
not $attrs->{"STRICT"} and my $handler = $attrs->{"ARRAYREF"}
!ll&&!rl&&r
021
MC/DC50%1/2
not $attrs->{"STRICT"} and my $handler = $attrs->{"ARRAYREF"}
not $attrs->{"STRICT"} my $handler = $attrs->{"ARRAYREF"}
Truth table66%2/3
not(A) and B
A= not $attrs->{"STRICT"}B= my $handler = $attrs->{"ARRAYREF"}
ABresult
0X0
100
111
877 1 local $Contextual::Return::uplevel = 2;
878  
879 # Array ref may be returned directly, or via RESULT{}...
880 1 my $array_ref = eval { $handler->(@{$attrs->{args}}) };
881 1 ▶ if ($recover) {
Branch: 2 branches
BranchTrueFalseTotal
if ($recover) { } 0 1 1
elsif ($@) { } 0 1 1
882 0 ▶ if (!$Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Contextual::Return::__RESULT__) 0 0 0
883 0 $Contextual::Return::__RESULT__ = [$array_ref];
884 }
885 0 scalar $recover->(@{$attrs->{args}});
886 }
887 elsif ($@) {
888 0 die $@;
889 }
890  
891 1 ▶ $array_ref = $Contextual::Return::__RESULT__->[0]
Branch: 1 branch
BranchTrueFalseTotal
if $Contextual::Return::__RESULT__ 0 1 1
892 if $Contextual::Return::__RESULT__;
893  
894 1 ▶ return @{$array_ref} if (ref $array_ref||q{}) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if (ref $array_ref || "") eq "ARRAY" 1 0 1
Condition50%1/2
ref $array_ref || ''
l!l
10
MC/DC0%0/1
ref $array_ref || ''
ref $array_ref
Truth table50%1/2
A
A= ref $array_ref
Aresult
11
00
895 }
896 # Return scalar object as one-elem list, if possible...
897 handler:
898 2 for my $context (qw(BOOL STR NUM VALUE SCALAR LAZY)) {
899 5 ▶ last if $attrs->{STRICT};
Branch: 1 branch
BranchTrueFalseTotal
if $attrs->{"STRICT"} 0 5 5
900 5 ▶ return $crv if exists $attrs->{$context};
Branch: 1 branch
BranchTrueFalseTotal
if exists $attrs->{$context} 2 3 5
901 }
902 0 $@ = _in_context "Can't call $attrs->{sub} in a list context";
903 0 ▶ if ($recover) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recover) { } 0 0 0
904 0 () = $recover->(@{$attrs->{args}});
905 }
906 else {
907 0 die $@;
908 }
909 }
910  
911 # Handle void context directly...
912 1104 ▶ if (!defined $wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $wantarray) 6 1098 1104
913 handler:
914 6 for my $context (qw(VOID DEFAULT)) {
915 9 ▶ if (!$attrs->{$context}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($attrs->{$context}) 3 6 9
916 3 ▶ last handler if $attrs->{STRICT};
Branch: 1 branch
BranchTrueFalseTotal
if $attrs->{"STRICT"} 0 3 3
917 3 next handler;
918 }
919  
920 6 eval { $attrs->{$context}->(@{$attrs->{args}}) };
921  
922 6 ▶ if ($recover) {
Branch: 2 branches
BranchTrueFalseTotal
if ($recover) { } 1 5 6
elsif ($@) { } 4 1 5
923 1 $recover->(@{$attrs->{args}});
924 }
925 elsif ($@) {
926 4 die $@;
927 }
928  
929 2 last handler;
930 }
931 2 ▶ if ($attrs->{STRICT}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrs->{"STRICT"}) 0 2 2
932 0 $@ = _in_context "Can't call $attrs->{sub} in a void context";
933 0 ▶ if ($recover) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recover) { } 0 0 0
934 0 () = $recover->(@{$attrs->{args}});
935 }
936 else {
937 0 die $@;
938 }
939 }
940 2 return;
941 }
942  
943 # Otherwise, defer evaluation by returning an object...
944 1098 return $crv;
945 }
946 558 }
947  
948 # Alias LAZY to SCALAR...
949 31 *LAZY = *SCALAR;
950  
951  
952 # Set $Data::Dumper::Freezer to 'Contextual::Return::FREEZE' to be able to
953 # dump contextual return values...
954  
955 31 my %operator_impl;
956  
957 31 my $no_handler_message = qr{
958 ^ Can't [ ] call [ ] .*? [ ] in [ ] [\w]+ [ ] context
959 | ^ [\w:]+ [ ] can't [ ] return [ ] a [ ] \w+ [ ] reference
960 }xms;
961  
962 0 ▶sub _flag_self_ref_in {
Subroutine _flag_self_ref_in: not called CC=6 SCAR=33.1
963 0 my ($data_ref, $obj_ref) = @_;
964 0 my $type = ref $data_ref;
965 0 ▶ return if !$type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 0 0 0
966 0 ▶ for my $ref ( $type eq 'SCALAR' ? ${$data_ref} : $type eq 'ARRAY' ? @{$data_ref} : ()) {
Branch: 2 branches
BranchTrueFalseTotal
$type eq 'SCALAR' ? : 0 0 0
$type eq 'ARRAY' ? : 0 0 0
967 31 ▶ no warnings 'numeric', 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
968 0 ▶ if (refaddr($ref) == refaddr($obj_ref)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::refaddr($ref) == builtin::refaddr($obj_ref)) 0 0 0
969 0 $ref = '<<<self-reference>>>';
970 }
971 }
972 }
973  
974 0 ▶sub FREEZE {
Subroutine FREEZE: not called CC=4 SCAR=28.9
Pod documented
975 0 my ($self) = @_;
976 0 my $attrs_ref = $attrs_of{refaddr $self};
977 0 my $args_ref = $attrs_ref->{args};
978  
979 0 my @no_handler;
980  
981 # Call appropriate operator handler, defusing and recording exceptions...
982 0 ▶ my $overloaded = sub {
Subroutine __ANON__: not called CC=5 SCAR=31.4
983 0 my ($context, $op) = @_;
984  
985 # Try the operator...
986 0 my $retval = eval { $operator_impl{$op}->($self,@{$args_ref}) };
987  
988 # Detect and report internal exceptions...
989 0 ▶ if (my $exception = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $exception = $@) 0 0 0
990 0 ▶ if ($exception =~ $no_handler_message) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exception =~ /$no_handler_message/) 0 0 0
991 0 push @no_handler, $context;
992 0 return ();
993 }
994 0 chomp $exception;
995 0 return { $context => "<<<Throws exception: $exception>>>" };
996 }
997  
998 # Detect self-referential overloadings (to avoid infinite recursion)...
999 {
1000 0 ▶ no warnings 'numeric', 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.2
1001 0 ▶ if (ref $retval eq 'REF' && eval{ ${$retval} == ${$self} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $retval eq "REF" and eval { do { ${$retval;} == ${$self;} } }) 0 0 0
Condition0%0/3
ref $retval eq "REF" and eval { do { ${$retval;} == ${$self;} } }
!ll&&!rl&&r
000
MC/DC0%0/2
ref $retval eq "REF" and eval { do { ${$retval;} == ${$self;} } }
ref $retval eq "REF" eval { do { ${$retval;} == ${$self;} } }
Truth table0%0/3
A and B
A= ref $retval eq "REF"B= eval { do { ${$retval;} == ${$self;} } }
ABresult
0X0
100
111
1002 0 return { $context => "<<<self-reference>>>" };
1003 }
1004 }
1005  
1006 # Normal return of contextual value labelled by context...
1007 0 return { $context => $retval };
1008 0 };
1009  
1010 0 my @values;
1011  
1012 # Where did this value originate?
1013 0 push @values, { ISA => 'Contextual::Return::Value' };
1014 0 push @values, { FROM => $attrs_ref->{sub} };
1015  
1016 # Does it return a value in void context?
1017 0 ▶ if (exists $attrs_ref->{VOID} || exists $attrs_ref->{DEFAULT}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $attrs_ref->{'VOID'} or exists $attrs_ref->{'DEFAULT'}) { } 0 0 0
Condition0%0/3
exists $attrs_ref->{"VOID"} or exists $attrs_ref->{"DEFAULT"}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $attrs_ref->{"VOID"} or exists $attrs_ref->{"DEFAULT"}
exists $attrs_ref->{"VOID"} exists $attrs_ref->{"DEFAULT"}
Truth table0%0/3
A or B
A= exists $attrs_ref->{"VOID"}B= exists $attrs_ref->{"DEFAULT"}
ABresult
1X1
011
000
1018 0 push @values, { VOID => undef };
1019 }
1020 else {
1021 0 push @no_handler, 'VOID';
1022 }
1023  
1024 # Generate list context value by "pretend" LIST handler...
1025 0 ▶ push @values, { LIST => eval{ [ _internal_LIST(sub{}, $self) ] } // do{ chomp $@; "<<<Throws exception: $@>>>"} };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
eval { do { [&_internal_LIST(sub { } , $self)] } } // do { chomp $@; "<<<Throws exception: $@>>>" }
l!l&&r!l&&!r
000
MC/DC0%0/2
eval { do { [&_internal_LIST(sub { } , $self)] } } // do { chomp $@; "<<<Throws exception: $@>>>" }
eval { do { [&_internal_LIST(sub { } , $self)] } } do { chomp $@; "<<<Throws exception: $@>>>" }
Truth table0%0/3
A // B
A= eval { do { [&_internal_LIST(sub { } , $self)] } }B= do { chomp $@; "<<<Throws exception: $@>>>" }
ABresult
1X1
011
000
1026 0 _flag_self_ref_in($values[-1]{LIST}, $self);
1027  
1028 # Generate scalar context values by calling appropriate handler...
1029 0 push @values, $overloaded->( STR => q{""} );
1030 0 push @values, $overloaded->( NUM => '0+' );
1031 0 push @values, $overloaded->( BOOL => 'bool' );
1032 0 push @values, $overloaded->( SCALARREF => '${}' );
1033 0 _flag_self_ref_in($values[-1]{SCALARREF}, $self);
1034 0 push @values, $overloaded->( ARRAYREF => '@{}' );
1035 0 _flag_self_ref_in($values[-1]{ARRAYREF}, $self);
1036 0 push @values, $overloaded->( CODEREF => '&{}' );
1037 0 push @values, $overloaded->( HASHREF => '%{}' );
1038 0 push @values, $overloaded->( GLOBREF => '*{}' );
1039  
1040 # Are there handlers for various "generic" super-contexts...
1041 0 my @fallbacks = grep { $attrs_ref->{$_} }
1042 qw< DEFAULT NONVOID SCALAR VALUE REF RECOVER >;
1043  
1044 0 push @values, { NO_HANDLER => \@no_handler };
1045 0 push @values, { FALLBACKS => \@fallbacks };
1046  
1047 # Temporarily replace object being dumped, by values found...
1048 0 $_[0] = \@values;
1049 }
1050  
1051 # Call this method on a contextual return value object to debug it...
1052  
1053 0 ▶sub DUMP {
Subroutine DUMP: not called CC=3 SCAR=24.8
Pod documented
1054 0 ▶ if (eval{ require Data::Dumper; 1; }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Data::Dumper; 1 } }) { } 0 0 0
1055 0 my ($crv) = @_;
1056 0 ▶ if (eval{ ref($crv)->isa('Contextual::Return::Value')}) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { ref($crv)->isa("Contextual::Return::Value") } }) 0 0 0
1057 0 Contextual::Return::FREEZE($crv);
1058 }
1059 0 local $Data::Dumper::Terse = 1;
1060 0 local $Data::Dumper::Indent = 1;
1061 0 my $dump = Data::Dumper::Dumper($crv);
1062 0 $dump =~ s<,\n \{><,ZZZZ{>msg;
1063 0 $dump =~ s<\n\s+>< >msg;
1064 0 $dump =~ s<,ZZZZ\{><\n {>msg;
1065 0 return $dump;
1066 }
1067 else {
1068 0 Carp::carp("Can't DUMP contextual return value (no Data::Dumper!)");
1069 0 return;
1070 }
1071 }
1072  
1073  
1074 package Contextual::Return::Value;
1075 31 ▶BEGIN { *_in_context = *Contextual::Return::_in_context; }
Subroutine BEGIN: called CC=1 SCAR=0.0
1076 31 ▶use Scalar::Util qw( refaddr );
Subroutine BEGIN: called CC=1 SCAR=0.0
1077  
1078 31 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.2
1079 %operator_impl = (
1080 39 ▶ q{""} => sub {
Subroutine __ANON__: called CC=12 SCAR=26.2
1081 39 my ($self) = @_;
1082 39 local $Contextual::Return::__RETOBJ__ = $self;
1083 31 ▶ no warnings 'redefine'; local *CORE::GLOBAL::caller = $smart_caller;
Subroutine BEGIN: called CC=1 SCAR=0.0
1084  
1085 39 my $attrs = $attrs_of{refaddr $self};
1086 handler:
1087 39 for my $context (qw(STR SCALAR LAZY VALUE NONVOID DEFAULT NUM)) {
1088 my $handler = $attrs->{$context}
1089 or $attrs->{STRICT} and last handler
1090 95 ▶ or next handler;
Branch: 1 branch
BranchTrueFalseTotal
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler or next handler 39 56 95
Condition60%3/5
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
l!l&&r!l&&!r
39056
$attrs->{"STRICT"} and last handler
!ll
560
MC/DC50%1/2
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
my $handler = $attrs->{$context} $attrs->{"STRICT"}
Truth table66%2/3
A or B
A= my $handler = $attrs->{$context}B= $attrs->{"STRICT"}
ABresult
1X1
011
000
1091  
1092 39 local $Contextual::Return::__RESULT__;
1093 39 local $Contextual::Return::uplevel = 2;
1094 39 my $rv = eval { $handler->(@{$attrs->{args}}) };
1095  
1096 39 ▶ if (my $recover = $attrs->{RECOVER}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $recover = $attrs->{'RECOVER'}) { } 4 35 39
elsif ($@) { } 3 32 35
1097 4 ▶ if (!$Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Contextual::Return::__RESULT__) 4 0 4
1098 4 $Contextual::Return::__RESULT__ = [$rv];
1099 }
1100 4 scalar $recover->(@{$attrs->{args}});
1101 }
1102 elsif ($@) {
1103 3 die $@;
1104 }
1105  
1106 36 ▶ if ($Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Contextual::Return::__RESULT__) 8 28 36
1107 8 $rv = $Contextual::Return::__RESULT__->[0];
1108 }
1109  
1110 36 ▶ if ( $attrs->{FIXED} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($attrs->{'FIXED'}) { } 2 34 36
elsif (not $attrs->{'ACTIVE'}) { } 34 0 34
1111 2 $_[0] = $rv;
1112 }
1113 elsif ( !$attrs->{ACTIVE} ) {
1114 0 ▶ $attrs->{$context} = sub { $rv };
Subroutine __ANON__: not called CC=1 SCAR=1.2
1115 }
1116 36 return $rv;
1117 }
1118 0 $@ = _in_context "Can't use return value of $attrs->{sub} as a string";
1119 0 ▶ if (my $recover = $attrs->{RECOVER}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $recover = $attrs->{'RECOVER'}) { } 0 0 0
1120 0 scalar $recover->(@{$attrs->{args}});
1121 }
1122 else {
1123 0 die $@;
1124 }
1125 },
1126  
1127 30 ▶ q{0+} => sub {
Subroutine __ANON__: called CC=12 SCAR=25.9
1128 30 my ($self) = @_;
1129 30 local $Contextual::Return::__RETOBJ__ = $self;
1130 31 ▶ no warnings 'redefine'; local *CORE::GLOBAL::caller = $smart_caller;
Subroutine BEGIN: called CC=1 SCAR=0.0
1131 30 my $attrs = $attrs_of{refaddr $self};
1132 handler:
1133 30 for my $context (qw(NUM SCALAR LAZY VALUE NONVOID DEFAULT STR)) {
1134 my $handler = $attrs->{$context}
1135 or $attrs->{STRICT} and last handler
1136 50 ▶ or next handler;
Branch: 1 branch
BranchTrueFalseTotal
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler or next handler 30 20 50
Condition60%3/5
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
l!l&&r!l&&!r
30020
$attrs->{"STRICT"} and last handler
!ll
200
MC/DC50%1/2
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
my $handler = $attrs->{$context} $attrs->{"STRICT"}
Truth table66%2/3
A or B
A= my $handler = $attrs->{$context}B= $attrs->{"STRICT"}
ABresult
1X1
011
000
1137  
1138 30 local $Contextual::Return::__RESULT__;
1139 30 local $Contextual::Return::uplevel = 2;
1140 30 my $rv = eval { $handler->(@{$attrs->{args}}) };
1141  
1142 30 ▶ if (my $recover = $attrs->{RECOVER}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $recover = $attrs->{'RECOVER'}) { } 5 25 30
elsif ($@) { } 3 22 25
1143 5 ▶ if (!$Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Contextual::Return::__RESULT__) 5 0 5
1144 5 $Contextual::Return::__RESULT__ = [$rv];
1145 }
1146 5 scalar $recover->(@{$attrs->{args}});
1147 }
1148 elsif ($@) {
1149 3 die $@;
1150 }
1151  
1152 27 ▶ if ($Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Contextual::Return::__RESULT__) 9 18 27
1153 9 $rv = $Contextual::Return::__RESULT__->[0];
1154 }
1155  
1156 27 ▶ if ( $attrs->{FIXED} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($attrs->{'FIXED'}) { } 1 26 27
elsif (not $attrs->{'ACTIVE'}) { } 26 0 26
1157 1 $_[0] = $rv;
1158 }
1159 elsif ( !$attrs->{ACTIVE} ) {
1160 26 ▶ $attrs->{$context} = sub { $rv };
Subroutine __ANON__: called CC=1 SCAR=0.0
1161 }
1162 27 return $rv;
1163 }
1164 0 $@ = _in_context "Can't use return value of $attrs->{sub} as a number";
1165 0 ▶ if (my $recover = $attrs->{RECOVER}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $recover = $attrs->{'RECOVER'}) { } 0 0 0
1166 0 scalar $recover->(@{$attrs->{args}});
1167 }
1168 else {
1169 0 die $@;
1170 }
1171 },
1172  
1173 33 ▶ q{bool} => sub {
Subroutine __ANON__: called CC=14 SCAR=28.2
1174 33 my ($self) = @_;
1175 33 local $Contextual::Return::__RETOBJ__ = $self;
1176 31 ▶ no warnings 'redefine'; local *CORE::GLOBAL::caller = $smart_caller;
Subroutine BEGIN: called CC=1 SCAR=0.0
1177 33 my $attrs = $attrs_of{refaddr $self};
1178  
1179 # Handle Calls in Pure Boolean context...
1180 33 ▶ my @PUREBOOL = $attrs->{want_pure_bool} ? ('PUREBOOL') : ();
Branch: 1 branch
BranchTrueFalseTotal
$attrs->{'want_pure_bool'} ? : 19 14 33
1181 33 $attrs->{want_pure_bool} = 0;
1182  
1183 handler:
1184 33 for my $context (@PUREBOOL, qw(BOOL STR NUM SCALAR LAZY VALUE NONVOID DEFAULT)) {
1185 my $handler = $attrs->{$context}
1186 or $context eq 'BOOL' and $attrs->{STRICT} and last handler
1187 56 ▶ or next handler;
Branch: 1 branch
BranchTrueFalseTotal
my $handler = $attrs->{$context} or $context eq "BOOL" and $attrs->{"STRICT"} and last handler or next handler 34 22 56
Condition62%5/8
my $handler = $attrs->{$context} or $context eq "BOOL" and $attrs->{"STRICT"} and last handler
l!l&&r!l&&!r
34022
$context eq "BOOL" and $attrs->{"STRICT"} and last handler
!ll
220
$context eq "BOOL" and $attrs->{"STRICT"}
!ll&&!rl&&r
2110
MC/DC33%1/3
my $handler = $attrs->{$context} or $context eq "BOOL" and $attrs->{"STRICT"} and last handler
my $handler = $attrs->{$context} $context eq "BOOL" $attrs->{"STRICT"}
Truth table75%3/4
A or B and C
A= my $handler = $attrs->{$context}B= $context eq "BOOL"C= $attrs->{"STRICT"}
ABCresult
1XX1
0111
00X0
0100
1188  
1189 34 local $Contextual::Return::__RESULT__;
1190 34 local $Contextual::Return::uplevel = 2;
1191 34 my $outer_sig_warn = $SIG{__WARN__};
1192 local $SIG{__WARN__}
1193 1 ▶ = sub{ return if $_[0] =~ /^Exiting \S+ via next/;
Subroutine __ANON__: called CC=3 SCAR=12.5
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ /^Exiting \S+ via next/ 0 1 1
1194 1 ▶ goto &{$outer_sig_warn} if $outer_sig_warn;
Branch: 1 branch
BranchTrueFalseTotal
if $outer_sig_warn 1 0 1
1195 0 warn @_;
1196 34 };
1197 34 my $rv = eval { $handler->(@{$attrs->{args}}) };
1198  
1199 33 ▶ if (my $recover = $attrs->{RECOVER}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $recover = $attrs->{'RECOVER'}) { } 4 29 33
elsif ($@) { } 0 29 29
1200 4 ▶ if (!$Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Contextual::Return::__RESULT__) 4 0 4
1201 4 $Contextual::Return::__RESULT__ = [$rv];
1202 }
1203 4 scalar $recover->(@{$attrs->{args}});
1204 }
1205 elsif ($@) {
1206 0 die $@;
1207 }
1208  
1209 33 ▶ if ($Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Contextual::Return::__RESULT__) 8 25 33
1210 8 $rv = $Contextual::Return::__RESULT__->[0];
1211 }
1212  
1213 33 ▶ if ( $attrs->{FIXED} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($attrs->{'FIXED'}) { } 1 32 33
elsif (not $attrs->{'ACTIVE'}) { } 32 0 32
1214 1 $_[0] = $rv;
1215 }
1216 elsif ( !$attrs->{ACTIVE} ) {
1217 32 ▶ $attrs->{$context} = sub { $rv };
Subroutine __ANON__: called CC=1 SCAR=0.0
1218 }
1219 33 return $rv;
1220 }
1221 0 $@ = _in_context "Can't use return value of $attrs->{sub} as a boolean";
1222 0 ▶ if (my $recover = $attrs->{RECOVER}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $recover = $attrs->{'RECOVER'}) { } 0 0 0
1223 0 scalar $recover->(@{$attrs->{args}});
1224 }
1225 else {
1226 0 die $@;
1227 }
1228 },
1229 24 ▶ '${}' => sub {
Subroutine __ANON__: called CC=16 SCAR=28.6
1230 24 my ($self) = @_;
1231 24 local $Contextual::Return::__RETOBJ__ = $self;
1232 31 ▶ no warnings 'redefine'; local *CORE::GLOBAL::caller = $smart_caller;
Subroutine BEGIN: called CC=1 SCAR=0.0
1233 24 my $attrs = $attrs_of{refaddr $self};
1234 handler:
1235 24 for my $context (qw(SCALARREF REF NONVOID DEFAULT)) {
1236 my $handler = $attrs->{$context}
1237 or $attrs->{STRICT} and last handler
1238 48 ▶ or next handler;
Branch: 1 branch
BranchTrueFalseTotal
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler or next handler 15 32 47
Condition80%4/5
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
l!l&&r!l&&!r
15033
$attrs->{"STRICT"} and last handler
!ll
321
MC/DC100%2/2
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
my $handler = $attrs->{$context} $attrs->{"STRICT"}
Truth table100%3/3
A or B
A= my $handler = $attrs->{$context}B= $attrs->{"STRICT"}
ABresult
1X1
011
000
1239  
1240 15 local $Contextual::Return::__RESULT__;
1241 15 local $Contextual::Return::uplevel = 2;
1242 15 my $rv = eval { $handler->(@{$attrs->{args}}) };
1243  
1244 15 ▶ if (my $recover = $attrs->{RECOVER}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $recover = $attrs->{'RECOVER'}) { } 1 14 15
elsif ($@) { } 0 14 14
1245 1 ▶ if (!$Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Contextual::Return::__RESULT__) 1 0 1
1246 1 $Contextual::Return::__RESULT__ = [$rv];
1247 }
1248 1 scalar $recover->(@{$attrs->{args}});
1249 }
1250 elsif ($@) {
1251 0 die $@;
1252 }
1253  
1254 15 ▶ if ($Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Contextual::Return::__RESULT__) 5 10 15
1255 5 $rv = $Contextual::Return::__RESULT__->[0];
1256 }
1257  
1258 # Catch bad behaviour...
1259 15 ▶ die _in_context "$context block did not return ",
Branch: 1 branch
BranchTrueFalseTotal
if ref $rv ne "SCALAR" and ref $rv ne "OBJ" 0 15 15
Condition33%1/3
ref $rv ne "SCALAR" and ref $rv ne "OBJ"
!ll&&!rl&&r
1500
MC/DC0%0/2
ref $rv ne "SCALAR" and ref $rv ne "OBJ"
ref $rv ne "SCALAR" ref $rv ne "OBJ"
Truth table33%1/3
A and B
A= ref $rv ne "SCALAR"B= ref $rv ne "OBJ"
ABresult
0X0
100
111
1260 "a suitable reference to the scalar dereference"
1261 if ref($rv) ne 'SCALAR' && ref($rv) ne 'OBJ';
1262  
1263 15 ▶ if ( $attrs->{FIXED} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($attrs->{'FIXED'}) { } 1 14 15
elsif (not $attrs->{'ACTIVE'}) { } 14 0 14
1264 1 $_[0] = $rv;
1265 }
1266 elsif ( !$attrs->{ACTIVE} ) {
1267 0 ▶ $attrs->{$context} = sub { $rv };
Subroutine __ANON__: not called CC=1 SCAR=1.2
1268 }
1269 15 return $rv;
1270 }
1271  
1272 9 ▶ if ($attrs->{STRICT}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrs->{"STRICT"}) 1 8 9
1273 1 $@ = _in_context "Call to $attrs->{sub} didn't return a scalar reference, as required <LOC>";
1274 1 ▶ if (my $recover = $attrs->{RECOVER}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $recover = $attrs->{'RECOVER'}) { } 0 1 1
1275 0 scalar $recover->(@{$attrs->{args}});
1276 }
1277 else {
1278 1 die $@;
1279 }
1280 }
1281  
1282 8 ▶ if ( $attrs->{FIXED} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrs->{"FIXED"}) 1 7 8
1283 1 $_[0] = \$self;
1284 }
1285 8 return \$self;
1286 },
1287 22 ▶ '@{}' => sub {
Subroutine __ANON__: called CC=24 SCAR=36.0
1288 22 my ($self) = @_;
1289 22 local $Contextual::Return::__RETOBJ__ = $self;
1290 31 ▶ no warnings 'redefine'; local *CORE::GLOBAL::caller = $smart_caller;
Subroutine BEGIN: called CC=1 SCAR=0.0
1291 22 my $attrs = $attrs_of{refaddr $self};
1292 22 local $Contextual::Return::__RESULT__;
1293 handler:
1294 22 for my $context (qw(ARRAYREF REF)) {
1295 my $handler = $attrs->{$context}
1296 or $attrs->{STRICT} and last handler
1297 28 ▶ or next handler;
Branch: 1 branch
BranchTrueFalseTotal
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler or next handler 15 12 27
Condition80%4/5
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
l!l&&r!l&&!r
15013
$attrs->{"STRICT"} and last handler
!ll
121
MC/DC100%2/2
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
my $handler = $attrs->{$context} $attrs->{"STRICT"}
Truth table100%3/3
A or B
A= my $handler = $attrs->{$context}B= $attrs->{"STRICT"}
ABresult
1X1
011
000
1298  
1299 15 local $Contextual::Return::uplevel = 2;
1300 15 my $rv = eval { $handler->(@{$attrs->{args}}) };
1301  
1302 15 ▶ if (my $recover = $attrs->{RECOVER}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $recover = $attrs->{'RECOVER'}) { } 1 14 15
elsif ($@) { } 0 14 14
1303 1 ▶ if (!$Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Contextual::Return::__RESULT__) 1 0 1
1304 1 $Contextual::Return::__RESULT__ = [$rv];
1305 }
1306 1 scalar $recover->(@{$attrs->{args}});
1307 }
1308 elsif ($@) {
1309 0 die $@;
1310 }
1311  
1312 15 ▶ if ($Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Contextual::Return::__RESULT__) 5 10 15
1313 5 $rv = $Contextual::Return::__RESULT__->[0];
1314 }
1315  
1316 # Catch bad behaviour...
1317 15 ▶ die _in_context "$context block did not return ",
Branch: 1 branch
BranchTrueFalseTotal
if ref $rv ne "ARRAY" and ref $rv ne "OBJ" 0 15 15
Condition33%1/3
ref $rv ne "ARRAY" and ref $rv ne "OBJ"
!ll&&!rl&&r
1500
MC/DC0%0/2
ref $rv ne "ARRAY" and ref $rv ne "OBJ"
ref $rv ne "ARRAY" ref $rv ne "OBJ"
Truth table33%1/3
A and B
A= ref $rv ne "ARRAY"B= ref $rv ne "OBJ"
ABresult
0X0
100
111
1318 "a suitable reference to the array dereference"
1319 if ref($rv) ne 'ARRAY' && ref($rv) ne 'OBJ';
1320  
1321 15 ▶ if ( $attrs->{FIXED} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($attrs->{'FIXED'}) { } 1 14 15
elsif (not $attrs->{'ACTIVE'}) { } 14 0 14
1322 1 $_[0] = $rv;
1323 }
1324 elsif ( !$attrs->{ACTIVE} ) {
1325 0 ▶ $attrs->{$context} = sub { $rv };
Subroutine __ANON__: not called CC=1 SCAR=1.2
1326 }
1327 15 return $rv;
1328 }
1329 handler:
1330 7 for my $context (qw(LIST VALUE NONVOID DEFAULT)) {
1331 9 ▶ last handler if $attrs->{STRICT};
Branch: 1 branch
BranchTrueFalseTotal
if $attrs->{"STRICT"} 1 8 9
1332 8 ▶ my $handler = $attrs->{$context}
Branch: 1 branch
BranchTrueFalseTotal
my $handler = $attrs->{$context} or next handler 6 2 8
1333 or next handler;
1334  
1335 6 local $Contextual::Return::uplevel = 2;
1336 6 my @rv = eval { $handler->(@{$attrs->{args}}) };
1337  
1338 6 ▶ if (my $recover = $attrs->{RECOVER}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $recover = $attrs->{'RECOVER'}) { } 0 6 6
elsif ($@) { } 0 6 6
1339 0 ▶ if (!$Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Contextual::Return::__RESULT__) 0 0 0
1340 0 $Contextual::Return::__RESULT__ = [@rv];
1341 }
1342 0 () = $recover->(@{$attrs->{args}});
1343 }
1344 elsif ($@) {
1345 0 die $@;
1346 }
1347  
1348 6 ▶ if ($Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Contextual::Return::__RESULT__) 0 6 6
1349 0 @rv = @{$Contextual::Return::__RESULT__->[0]};
1350 }
1351  
1352 6 ▶ if ( $attrs->{FIXED} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($attrs->{'FIXED'}) { } 1 5 6
elsif (not $attrs->{'ACTIVE'}) { } 5 0 5
1353 1 $_[0] = \@rv;
1354 }
1355 elsif ( !$attrs->{ACTIVE} ) {
1356 0 ▶ $attrs->{$context} = sub { @rv };
Subroutine __ANON__: not called CC=1 SCAR=1.2
1357 }
1358 6 return \@rv;
1359 }
1360  
1361 1 ▶ if ($attrs->{STRICT}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($attrs->{"STRICT"}) 1 0 1
1362 1 $@ = _in_context "Call to $attrs->{sub} didn't return an array reference, as required <LOC>";
1363 1 ▶ if (my $recover = $attrs->{RECOVER}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $recover = $attrs->{'RECOVER'}) { } 0 1 1
1364 0 scalar $recover->(@{$attrs->{args}});
1365 }
1366 else {
1367 1 die $@;
1368 }
1369 }
1370  
1371 0 return [ $self ];
1372 },
1373 16 ▶ '%{}' => sub {
Subroutine __ANON__: called CC=14 SCAR=27.8
1374 16 my ($self) = @_;
1375 16 local $Contextual::Return::__RETOBJ__ = $self;
1376 31 ▶ no warnings 'redefine'; local *CORE::GLOBAL::caller = $smart_caller;
Subroutine BEGIN: called CC=1 SCAR=0.0
1377 16 my $attrs = $attrs_of{refaddr $self};
1378 handler:
1379 16 for my $context (qw(HASHREF REF NONVOID DEFAULT)) {
1380 my $handler = $attrs->{$context}
1381 or $attrs->{STRICT} and last handler
1382 16 ▶ or next handler;
Branch: 1 branch
BranchTrueFalseTotal
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler or next handler 15 0 15
Condition60%3/5
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
l!l&&r!l&&!r
1501
$attrs->{"STRICT"} and last handler
!ll
01
MC/DC0%0/2
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
my $handler = $attrs->{$context} $attrs->{"STRICT"}
Truth table66%2/3
A or B
A= my $handler = $attrs->{$context}B= $attrs->{"STRICT"}
ABresult
1X1
011
000
1383  
1384 15 local $Contextual::Return::__RESULT__;
1385 15 local $Contextual::Return::uplevel = 2;
1386 15 my $rv = eval { $handler->(@{$attrs->{args}}) };
1387  
1388 15 ▶ if (my $recover = $attrs->{RECOVER}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $recover = $attrs->{'RECOVER'}) { } 1 14 15
elsif ($@) { } 0 14 14
1389 1 ▶ if (!$Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Contextual::Return::__RESULT__) 1 0 1
1390 1 $Contextual::Return::__RESULT__ = [$rv];
1391 }
1392 1 scalar $recover->(@{$attrs->{args}});
1393 }
1394 elsif ($@) {
1395 0 die $@;
1396 }
1397  
1398 15 ▶ if ($Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Contextual::Return::__RESULT__) 5 10 15
1399 5 $rv = $Contextual::Return::__RESULT__->[0];
1400 }
1401  
1402 # Catch bad behaviour...
1403 15 ▶ die _in_context "$context block did not return ",
Branch: 1 branch
BranchTrueFalseTotal
if ref $rv ne "HASH" and ref $rv ne "OBJ" 0 15 15
Condition33%1/3
ref $rv ne "HASH" and ref $rv ne "OBJ"
!ll&&!rl&&r
1500
MC/DC0%0/2
ref $rv ne "HASH" and ref $rv ne "OBJ"
ref $rv ne "HASH" ref $rv ne "OBJ"
Truth table33%1/3
A and B
A= ref $rv ne "HASH"B= ref $rv ne "OBJ"
ABresult
0X0
100
111
1404 "a suitable reference to the hash dereference"
1405 if ref($rv) ne 'HASH' && ref($rv) ne 'OBJ';
1406  
1407 15 ▶ if ( $attrs->{FIXED} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($attrs->{'FIXED'}) { } 1 14 15
elsif (not $attrs->{'ACTIVE'}) { } 14 0 14
1408 1 $_[0] = $rv;
1409 }
1410 elsif ( !$attrs->{ACTIVE} ) {
1411 14 ▶ $attrs->{$context} = sub { $rv };
Subroutine __ANON__: called CC=1 SCAR=0.0
1412 }
1413 15 return $rv;
1414 }
1415 1 $@ = _in_context "Call to $attrs->{sub} didn't return a hash reference, as required <LOC>";
1416 1 ▶ if (my $recover = $attrs->{RECOVER}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $recover = $attrs->{'RECOVER'}) { } 0 1 1
1417 0 scalar $recover->(@{$attrs->{args}});
1418 }
1419 else {
1420 1 die $@;
1421 }
1422 },
1423 7 ▶ '&{}' => sub {
Subroutine __ANON__: called CC=14 SCAR=30.7
1424 7 my ($self) = @_;
1425 7 local $Contextual::Return::__RETOBJ__ = $self;
1426 31 ▶ no warnings 'redefine'; local *CORE::GLOBAL::caller = $smart_caller;
Subroutine BEGIN: called CC=1 SCAR=0.0
1427 7 my $attrs = $attrs_of{refaddr $self};
1428 handler:
1429 7 for my $context (qw(CODEREF REF NONVOID DEFAULT)) {
1430 my $handler = $attrs->{$context}
1431 or $attrs->{STRICT} and last handler
1432 7 ▶ or next handler;
Branch: 1 branch
BranchTrueFalseTotal
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler or next handler 7 0 7
Condition20%1/5
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
l!l&&r!l&&!r
700
$attrs->{"STRICT"} and last handler
!ll
00
MC/DC0%0/2
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
my $handler = $attrs->{$context} $attrs->{"STRICT"}
Truth table33%1/3
A or B
A= my $handler = $attrs->{$context}B= $attrs->{"STRICT"}
ABresult
1X1
011
000
1433  
1434 7 local $Contextual::Return::__RESULT__;
1435 7 local $Contextual::Return::uplevel = 2;
1436 7 my $rv = eval { $handler->(@{$attrs->{args}}) };
1437  
1438 7 ▶ if (my $recover = $attrs->{RECOVER}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $recover = $attrs->{'RECOVER'}) { } 1 6 7
elsif ($@) { } 0 6 6
1439 1 ▶ if (!$Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Contextual::Return::__RESULT__) 1 0 1
1440 1 $Contextual::Return::__RESULT__ = [$rv];
1441 }
1442 1 scalar $recover->(@{$attrs->{args}});
1443 }
1444 elsif ($@) {
1445 0 die $@;
1446 }
1447  
1448 7 ▶ if ($Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Contextual::Return::__RESULT__) 2 5 7
1449 2 $rv = $Contextual::Return::__RESULT__->[0];
1450 }
1451  
1452 # Catch bad behaviour...
1453 7 ▶ die _in_context "$context block did not return ",
Branch: 1 branch
BranchTrueFalseTotal
if ref $rv ne "CODE" and ref $rv ne "OBJ" 0 7 7
Condition33%1/3
ref $rv ne "CODE" and ref $rv ne "OBJ"
!ll&&!rl&&r
700
MC/DC0%0/2
ref $rv ne "CODE" and ref $rv ne "OBJ"
ref $rv ne "CODE" ref $rv ne "OBJ"
Truth table33%1/3
A and B
A= ref $rv ne "CODE"B= ref $rv ne "OBJ"
ABresult
0X0
100
111
1454 "a suitable reference to the subroutine dereference"
1455 if ref($rv) ne 'CODE' && ref($rv) ne 'OBJ';
1456  
1457 7 ▶ if ( $attrs->{FIXED} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($attrs->{'FIXED'}) { } 1 6 7
elsif (not $attrs->{'ACTIVE'}) { } 6 0 6
1458 1 $_[0] = $rv;
1459 }
1460 elsif ( !$attrs->{ACTIVE} ) {
1461 0 ▶ $attrs->{$context} = sub { $rv };
Subroutine __ANON__: not called CC=1 SCAR=1.2
1462 }
1463 7 return $rv;
1464 }
1465 0 $@ = _in_context "Call to $attrs->{sub} didn't return a subroutine reference, as required <LOC>";
1466 0 ▶ if (my $recover = $attrs->{RECOVER}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $recover = $attrs->{'RECOVER'}) { } 0 0 0
1467 0 scalar $recover->(@{$attrs->{args}});
1468 }
1469 else {
1470 0 die $@;
1471 }
1472 },
1473 7 ▶ '*{}' => sub {
Subroutine __ANON__: called CC=14 SCAR=30.7
1474 7 my ($self) = @_;
1475 7 local $Contextual::Return::__RETOBJ__ = $self;
1476 31 ▶ no warnings 'redefine'; local *CORE::GLOBAL::caller = $smart_caller;
Subroutine BEGIN: called CC=1 SCAR=0.0
1477 7 my $attrs = $attrs_of{refaddr $self};
1478 handler:
1479 7 for my $context (qw(GLOBREF REF NONVOID DEFAULT)) {
1480 my $handler = $attrs->{$context}
1481 or $attrs->{STRICT} and last handler
1482 7 ▶ or next handler;
Branch: 1 branch
BranchTrueFalseTotal
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler or next handler 7 0 7
Condition20%1/5
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
l!l&&r!l&&!r
700
$attrs->{"STRICT"} and last handler
!ll
00
MC/DC0%0/2
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
my $handler = $attrs->{$context} $attrs->{"STRICT"}
Truth table33%1/3
A or B
A= my $handler = $attrs->{$context}B= $attrs->{"STRICT"}
ABresult
1X1
011
000
1483  
1484 7 local $Contextual::Return::__RESULT__;
1485 7 local $Contextual::Return::uplevel = 2;
1486 7 my $rv = eval { $handler->(@{$attrs->{args}}) };
1487  
1488 7 ▶ if (my $recover = $attrs->{RECOVER}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $recover = $attrs->{'RECOVER'}) { } 1 6 7
elsif ($@) { } 0 6 6
1489 1 ▶ if (!$Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Contextual::Return::__RESULT__) 1 0 1
1490 1 $Contextual::Return::__RESULT__ = [$rv];
1491 }
1492 1 scalar $recover->(@{$attrs->{args}});
1493 }
1494 elsif ($@) {
1495 0 die $@;
1496 }
1497  
1498 7 ▶ if ($Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Contextual::Return::__RESULT__) 2 5 7
1499 2 $rv = $Contextual::Return::__RESULT__->[0];
1500 }
1501  
1502 # Catch bad behaviour...
1503 7 ▶ die _in_context "$context block did not return ",
Branch: 1 branch
BranchTrueFalseTotal
if ref $rv ne "GLOB" and ref $rv ne "OBJ" 0 7 7
Condition33%1/3
ref $rv ne "GLOB" and ref $rv ne "OBJ"
!ll&&!rl&&r
700
MC/DC0%0/2
ref $rv ne "GLOB" and ref $rv ne "OBJ"
ref $rv ne "GLOB" ref $rv ne "OBJ"
Truth table33%1/3
A and B
A= ref $rv ne "GLOB"B= ref $rv ne "OBJ"
ABresult
0X0
100
111
1504 "a suitable reference to the typeglob dereference"
1505 if ref($rv) ne 'GLOB' && ref($rv) ne 'OBJ';
1506  
1507 7 ▶ if ( $attrs->{FIXED} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($attrs->{'FIXED'}) { } 1 6 7
elsif (not $attrs->{'ACTIVE'}) { } 6 0 6
1508 1 $_[0] = $rv;
1509 }
1510 elsif ( !$attrs->{ACTIVE} ) {
1511 0 ▶ $attrs->{$context} = sub { $rv };
Subroutine __ANON__: not called CC=1 SCAR=1.2
1512 }
1513 7 return $rv;
1514 }
1515 0 $@ = _in_context "Call to $attrs->{sub} didn't return a typeglob reference, as required <LOC>";
1516 0 ▶ if (my $recover = $attrs->{RECOVER}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $recover = $attrs->{'RECOVER'}) { } 0 0 0
1517 0 scalar $recover->(@{$attrs->{args}});
1518 }
1519 else {
1520 0 die $@;
1521 }
1522 },
1523 31 );
1524 }
1525  
1526 31 ▶use overload %operator_impl, fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
1527  
1528 245 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=6.9
1529 245 my ($id) = refaddr shift;
1530 245 my $attrs = $attrs_of{$id};
1531 31 ▶ no warnings 'redefine'; local *CORE::GLOBAL::caller = $smart_caller;
Subroutine BEGIN: called CC=1 SCAR=0.0
1532 245 ▶ if (my $handler = $attrs->{CLEANUP}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $handler = $attrs->{"CLEANUP"}) 13 232 245
1533 13 $handler->(@{ $attrs->{args} });
1534 }
1535 245 delete $attrs_of{$id};
1536 245 return;
1537 }
1538  
1539 31 my $NO_SUCH_METHOD = qr/\ACan't (?:locate|call)(?: class| object)? method/ms;
1540  
1541 # Forward metainformation requests to actual class...
1542 7 ▶sub can {
Subroutine can: called CC=2 SCAR=6.9
1543 7 my ($invocant) = @_;
1544 # Only forward requests on actual C::R::V objects...
1545 7 ▶ if (ref $invocant) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $invocant) 6 1 7
1546 6 our $AUTOLOAD = 'can';
1547 6 goto &AUTOLOAD;
1548 }
1549  
1550 # Refer requests on classes to actual class hierarchy...
1551 1 return $invocant->SUPER::can(@_[1..$#_]);
1552 }
1553  
1554 2 ▶sub isa {
Subroutine isa: called CC=2 SCAR=6.9
1555 # Only forward requests on actual C::R::V objects...
1556 2 my ($invocant) = @_;
1557 2 ▶ if (ref $invocant) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $invocant) 1 1 2
1558 1 our $AUTOLOAD = 'isa';
1559 1 goto &AUTOLOAD;
1560 }
1561  
1562 # Refer requests on classes to actual class hierarchy...
1563 1 return $invocant->SUPER::isa(@_[1..$#_]);
1564 }
1565  
1566  
1567 22 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=32 SCAR=44.2
1568 22 my ($self) = @_;
1569 22 our $AUTOLOAD;
1570  
1571 22 ▶ my ($requested_method) = $AUTOLOAD =~ m{ .* :: (.*) }xms ? $1 : $AUTOLOAD;
Branch: 1 branch
BranchTrueFalseTotal
$Contextual::Return::Value::AUTOLOAD =~ / .* :: (.*) /msx ? : 15 7 22
1572  
1573 22 ▶ my $attrs = $attrs_of{refaddr $self} || {};
Condition50%1/2
$attrs_of{builtin::refaddr($self)} || {}
l!l
220
MC/DC0%0/1
$attrs_of{builtin::refaddr($self)} || {}
$attrs_of{builtin::refaddr($self)}
Truth table50%1/2
A
A= $attrs_of{builtin::refaddr($self)}
Aresult
11
00
1574 22 local $Contextual::Return::__RETOBJ__ = $self;
1575 31 ▶ no warnings 'redefine'; local *CORE::GLOBAL::caller = $smart_caller;
Subroutine BEGIN: called CC=1 SCAR=0.0
1576  
1577 # First, see if there is a method call handler...
1578 22 ▶ if (my $context_handler = $attrs->{METHOD}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $context_handler = $attrs->{"METHOD"}) 8 14 22
1579 8 local $Contextual::Return::__RESULT__;
1580 8 local $Contextual::Return::uplevel = 2;
1581 8 my @method_handlers = eval { $context_handler->(@{$attrs->{args}}) };
1582  
1583 8 ▶ if (my $recover = $attrs->{RECOVER}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $recover = $attrs->{'RECOVER'}) { } 0 8 8
elsif ($@) { } 0 8 8
1584 0 ▶ if (!$Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Contextual::Return::__RESULT__) 0 0 0
1585 0 $Contextual::Return::__RESULT__ = [\@method_handlers];
1586 }
1587 0 scalar $recover->(@{$attrs->{args}});
1588 }
1589 elsif ($@) {
1590 0 die $@;
1591 }
1592  
1593 8 ▶ if ($Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Contextual::Return::__RESULT__) 0 8 8
1594 0 @method_handlers = @{$Contextual::Return::__RESULT__};
1595 }
1596  
1597 # Locate the correct method handler (if any)...
1598 MATCHER:
1599 8 ▶ while (my ($matcher, $method_handler) = splice @method_handlers, 0, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@method_handlers, 0, 2)) 16 1 17
1600  
1601 16 ▶ if (ref($matcher) eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $matcher eq 'ARRAY') { } 3 13 16
elsif (not $requested_method =~ /$matcher/) { } 8 5 13
1602 next MATCHER
1603 3 ▶ if !grep { $requested_method =~ $_ } @{$matcher};
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$requested_method =~ /$_/;} @{$matcher;} 1 2 3
1604 }
1605 elsif ($requested_method !~ $matcher) {
1606 8 next MATCHER;
1607 }
1608  
1609 7 shift;
1610 7 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 7 7
1611 0 my @result = eval {
1612 0 local $_ = $requested_method;
1613 0 $method_handler->($self,@_);
1614 };
1615 0 ▶ die _in_context $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
1616 0 return @result;
1617 }
1618 else {
1619 7 my $result = eval {
1620 7 local $_ = $requested_method;
1621 7 $method_handler->($self,@_);
1622 };
1623 7 ▶ die _in_context $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 7 7
1624 7 return $result;
1625 }
1626 }
1627 }
1628  
1629 # Next, try to create an object on which to call the method...
1630 handler:
1631 15 for my $context (qw(OBJREF STR SCALAR LAZY VALUE NONVOID DEFAULT)) {
1632 my $handler = $attrs->{$context}
1633 or $attrs->{STRICT} and last handler
1634 61 ▶ or next handler;
Branch: 1 branch
BranchTrueFalseTotal
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler or next handler 10 51 61
Condition60%3/5
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
l!l&&r!l&&!r
10051
$attrs->{"STRICT"} and last handler
!ll
510
MC/DC50%1/2
my $handler = $attrs->{$context} or $attrs->{"STRICT"} and last handler
my $handler = $attrs->{$context} $attrs->{"STRICT"}
Truth table66%2/3
A or B
A= my $handler = $attrs->{$context}B= $attrs->{"STRICT"}
ABresult
1X1
011
000
1635  
1636 10 local $Contextual::Return::__RESULT__;
1637 10 local $Contextual::Return::uplevel = 2;
1638 10 my $object = eval { $handler->(@{$attrs->{args}}) };
1639  
1640 10 ▶ if (my $recover = $attrs->{RECOVER}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $recover = $attrs->{'RECOVER'}) { } 0 10 10
elsif ($@) { } 0 10 10
1641 0 ▶ if (!$Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Contextual::Return::__RESULT__) 0 0 0
1642 0 $Contextual::Return::__RESULT__ = [$object];
1643 }
1644 0 scalar $recover->(@{$attrs->{args}});
1645 }
1646 elsif ($@) {
1647 0 die $@;
1648 }
1649  
1650 10 ▶ if ($Contextual::Return::__RESULT__) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Contextual::Return::__RESULT__) 0 10 10
1651 0 $object = $Contextual::Return::__RESULT__->[0];
1652 }
1653  
1654 10 ▶ if ( $attrs->{FIXED} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($attrs->{'FIXED'}) { } 1 9 10
elsif (not $attrs->{'ACTIVE'}) { } 9 0 9
1655 1 $_[0] = $object;
1656 }
1657 elsif ( !$attrs->{ACTIVE} ) {
1658 0 ▶ $attrs->{$context} = sub { $object };
Subroutine __ANON__: not called CC=1 SCAR=1.2
1659 }
1660 10 shift;
1661  
1662 10 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 10 10
1663 0 my @result = eval { $object->$requested_method(@_) };
1664 0 my $exception = $@;
1665 0 ▶ return @result if !$exception;
Branch: 1 branch
BranchTrueFalseTotal
unless $exception 0 0 0
1666 0 ▶ die _in_context $exception if $exception !~ $NO_SUCH_METHOD;
Branch: 1 branch
BranchTrueFalseTotal
unless $exception =~ /$NO_SUCH_METHOD/ 0 0 0
1667 }
1668 else {
1669 10 my $result = eval { $object->$requested_method(@_) };
1670 10 my $exception = $@;
1671 10 ▶ return $result if !$exception;
Branch: 1 branch
BranchTrueFalseTotal
unless $exception 6 4 10
1672 4 ▶ die _in_context $exception if $exception !~ $NO_SUCH_METHOD;
Branch: 1 branch
BranchTrueFalseTotal
unless $exception =~ /$NO_SUCH_METHOD/ 1 3 4
1673 }
1674 3 $@ = _in_context "Can't call method '$requested_method' on $context value returned by $attrs->{sub}";
1675 3 ▶ if (my $recover = $attrs->{RECOVER}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $recover = $attrs->{'RECOVER'}) { } 0 3 3
1676 0 scalar $recover->(@{$attrs->{args}});
1677 }
1678 else {
1679 3 die $@;
1680 }
1681 }
1682  
1683 # Otherwise, the method cannot be called, so react accordingly...
1684 5 $@ = _in_context "Can't call method '$requested_method' on value returned by $attrs->{sub}";
1685 5 ▶ if (my $recover = $attrs->{RECOVER}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $recover = $attrs->{'RECOVER'}) { } 0 5 5
1686 0 return scalar $recover->(@{$attrs->{args}});
1687 }
1688 else {
1689 5 die $@;
1690 }
1691 }
1692  
1693 package Contextual::Return::Lvalue;
1694  
1695 10 ▶sub TIESCALAR {
Subroutine TIESCALAR: called CC=1 SCAR=0.0
1696 10 my ($package, @handler) = @_;
1697 10 return bless {@handler}, $package;
1698 }
1699  
1700 # Handle calls that are lvalues...
1701 3 ▶sub STORE {
Subroutine STORE: called CC=2 SCAR=7.0
1702 3 local *CALLER::_ = \$_;
1703 3 local *_ = \$_[1];
1704 3 local $Contextual::Return::uplevel = 1;
1705 31 ▶ no warnings 'redefine'; local *CORE::GLOBAL::caller = $smart_caller;
Subroutine BEGIN: called CC=1 SCAR=0.0
1706 3 local $Contextual::Return::__RESULT__;
1707  
1708 3 my $rv = $_[0]{LVALUE}( @{$_[0]{args}} );
1709  
1710 3 ▶ return $rv if !$Contextual::Return::__RESULT__;
Branch: 1 branch
BranchTrueFalseTotal
unless $Contextual::Return::__RESULT__ 3 0 3
1711 0 return $Contextual::Return::__RESULT__->[0];
1712 }
1713  
1714 # Handle calls that are rvalues...
1715 19 ▶sub FETCH {
Subroutine FETCH: called CC=3 SCAR=11.3
1716 19 local $Contextual::Return::uplevel = 1;
1717 31 ▶ no warnings 'redefine'; local *CORE::GLOBAL::caller = $smart_caller;
Subroutine BEGIN: called CC=1 SCAR=0.0
1718 19 local $Contextual::Return::__RESULT__;
1719  
1720 19 ▶ my $rv = $_[0]{RVALUE} ? $_[0]{RVALUE}( @{$_[0]{args}} ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'RVALUE'} ? : 19 0 19
1721  
1722 19 ▶ return $rv if !$Contextual::Return::__RESULT__;
Branch: 1 branch
BranchTrueFalseTotal
unless $Contextual::Return::__RESULT__ 19 0 19
1723 0 return $Contextual::Return::__RESULT__->[0];
1724 }
1725  
1726 0 ▶sub DESTROY {};
Subroutine DESTROY: not called CC=1 SCAR=0.0
1727  
1728 31 1; # Magic true value required at end of module
1729  
1730 __END__
↑ Summary Return/Failure.pm »