{
# if the pattern gets silently re-parsed, ensure that any eval'ed
# code blocks get the correct lexical scope. The overloading of
# concat, along with the modification of the text of the code block,
# ensures that it has to be re-compiled.
{
package OL_MOD;
use overload
q{""} => sub { my ($pat) = @_; $pat->[0] },
q{.} => sub {
my ($a1, $a2) = @_;
$a1 = $a1->[0] if ref $a1;
$a2 = $a2->[0] if ref $a2;
my $s = "$a1$a2";
$s =~ s/x_var/y_var/;
bless [ $s ];
},
;
}
BEGIN {
overload::constant qr => sub { bless [ $_[0] ], 'OL_MOD' };
}
$::x_var = "ABC";
my $x_var = "abc";
$::y_var = "XYZ";
my $y_var = "xyz";
use re 'eval';
my $a = 'a';
print qq[ok - 1\n] if "xyz" =~ m{^(??{ $x_var })$}; # OL_MOD
print qq[ok - 2\n] if "xyza" =~ m{^(??{ $x_var })$a$}; # OL_MOD runtime"
}
extract from re/overload.t
The runtime test is working but not the first one
HEAD=d7aa198ab3b6adacbee32be33e189976e495be60