Subject: | Contextual::Return effects caller() |
Contextual::Return effects the call stack of the block being returned
thus reducing its transparency.
sub contextual_caller {
return LIST { caller }
SCALAR { scalar caller }
}
sub wantarray_caller {
return wantarray ? caller
: scalar caller
}
These two functions should be equivalent but contextual_caller() returns
"Contextual::Return" and wantarray_caller() returns "main" thus exposing
that LIST and SCALAR are not taking a block but a subroutine. Attached
is a test file for this.
Sub::Uplevel might come in handy. This should also eliminate the hack
for Carp.
Subject: | caller.t |
use Contextual::Return;
use warnings;
use Test::More 'no_plan';
sub contextual_caller {
return LIST { caller }
SCALAR { scalar caller }
}
sub wantarray_caller {
return wantarray ? caller : scalar caller;
}
is_deeply [contextual_caller], [wantarray_caller];
is scalar contextual_caller, scalar wantarray_caller;