Fix bug with (??{$overload}) regexp caching
When a scalar is returned from (??{...}) inside a regexp, it get com-
piled into a regexp if it is not one already. Then the regexp is sup-
posed to be cached on that scalar (in magic), so that the same scalar
returned again will not require another compilation.
This has never worked correctly with references, because the value was
being cached against the returned scalar itself, whereas the *refer-
ent* of a returned reference was being checked for qr magic.
Commit
e4bfbed39b disabled caching for all scalars except references
to overloaded objects. This is the result of copy the return value
to a new mortal scalar. The actual returned scalar then remains
untouched.
So the only case in which the cache value was used was incorrect:
namely, when the regexp was cached against a reference to an over-
loaded object, and a later code block returned a reference to that
reference:
$\="\n";
{ package o; use overload '""'=>sub { "abc" } }
$x = bless [],"o";
$y = \$x;
($y_addr = "$y") =~ y/()//d; # REF(0x7fcb9c02ef08) -> REF0x7fcb9c02ef08
print "$x$y";
print "abc$y_addr" =~ /$x$y/;
print "abc$y_addr" =~ /(??{$x})(??{$y})/; # does not match; should
print "abcabc" =~ /(??{$x})(??{$y})/; # matches!
print "__END__";
__END__
Output:
abcREF(0x7ff37182ef68)
0x7ff37182ef68
1
__END__
Should be:
abcREF(0x7ff37182ef68)
0x7ff37182ef68
1
__END__
This commit corrects the logic that checks for cached qr magic, effec-
tively disabling the cache altogether.
A forthcoming commit will reënable it (if all goes as planned).