Make (??{$tied_ovrld}) see the right $1
authorFather Chrysostomos <sprout@cpan.org>
Mon, 25 Nov 2013 02:12:04 +0000 (18:12 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Mon, 25 Nov 2013 03:57:07 +0000 (19:57 -0800)
commit2685dc2d9a9865ac92971890d053145da562c094
treec4494cded180af14f0accda3737492f37488a23d
parentbdbc68045b07fa332b168aaca9181a6c703a57bd
Make (??{$tied_ovrld}) see the right $1

I can return $1 from a regexp code block and it refers to the last
match *within* the block:

"aab" =~ /(a)((??{"b" =~ m|(.)|; $1}))/;
print "[$1 $2]\n";

Output:
[a b]

Even via a tied variable’s FETCH method:

sub ReEvalTieTest::TIESCALAR {bless[], "ReEvalTieTest"}
sub ReEvalTieTest::FETCH { "$1" }
tie my $t, "ReEvalTieTest";
"aab" =~ /(a)((??{"b" =~ m|(.)|; $t}))/;
print "[$1 $2]\n";

Output:
[a b]

But not if I assign a reference to an overloaded object to the tied
variable first:

sub ReEvalTieTest::TIESCALAR {bless[], "ReEvalTieTest"}
sub ReEvalTieTest::STORE{}
sub ReEvalTieTest::FETCH { "$1" }
tie my $t, "ReEvalTieTest";
{ package o; use overload '""'=>sub { "abc" } }
$t = bless [], "o";
"aab" =~ /(a)((??{"b" =~ m|(.)|; $t}))/;
print "[$1 $2]\n";

Output:
[a a]

$1 now refers to the outer pattern, not the inner pattern.

The code that handles the return value of code blocks was not check-
ing get-magic before overloading.

This commit fixes it to do that.
regexec.c
t/re/pat_re_eval.t