Amb
view release on metacpan or search on metacpan
local $Carp::CarpLevel = 3 unless $debug;
confess "Can't call $_[0]\(\) that way";
}
sub patch
{
my ($name, $xop, $cv, $upcontext) = @_;
printf("$name: patch at COP( 0x%x)\n", $$xop) if $debug;
my $cv_frame = $cv ? B::svref_2object($cv) : B::main_cv;
# enter other CV's padlist
my $savecp = B::cv_pad;
B::cv_pad( $cv_frame);
my $psm = B::GVOP-> new( 'gv', 0, \&after);
# calling ops
my $gc2 = B::UNOP-> new( 'null', 0, $psm);
my $gc3 = B::UNOP-> new( 'entersub', 0, $gc2);
my $cop = B::COP-> new( 0, '', 0); # this line appears as a calling point for after()
# this is the COP we put $cop after
my $gs = $xop-> sibling-> sibling;
if ( ref($gs) eq 'B::NULL') {
fail $what unless $up;
my $op = Amb::caller_op($up);
fail $what unless $op and ref($op) eq 'B::COP';
# ensure that the call is inside if(...) statement
my $x = $op-> sibling;
fail $what unless $x and ref($x) eq 'B::UNOP';
$x = $x-> first;
fail $what unless $x and ref($x) eq 'B::LOGOP' and $x-> name =~ /^(cond_expr|and)$/;
# get the cv frame that has called
my $upper = PadWalker::_upcontext(2);
my $cx;
if ( $upper) {
$cx = Amb::context_cv($upper);
fail $what unless $cx and ref($cx) eq 'CODE';
}
return $op, $cx, $up;
}
( run in 0.753 second using v1.01-cache-2.11-cpan-df04353d9ac )