summaryrefslogtreecommitdiff
path: root/t/lib/strict
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2011-10-12 14:01:50 +0100
committerDavid Mitchell <davem@iabyn.com>2012-06-13 13:25:50 +0100
commitd63c20f27b4a88c274844b2b635deb3c6588cccd (patch)
tree419e8d46117855aa07627636841d9a7208f0320e /t/lib/strict
parent2866decb530d50f622ad6853fed7f30562e474ce (diff)
downloadperl-d63c20f27b4a88c274844b2b635deb3c6588cccd.tar.gz
make qr/(?{})/ behave with closures
With this commit, qr// with a literal (compile-time) code block will Do the Right Thing as regards closures and the scope of lexical vars; in particular, the following now creates three regexes that match 1, 2 and 3: for my $i (0..2) { push @r, qr/^(??{$i})$/; } "1" =~ $r[1]; # matches Previously, $i would be evaluated as undef in all 3 patterns. This is achieved by wrapping the compilation of the pattern within a new anonymous CV, which is then attached to the pattern. At run-time pp_qr() clones the CV as well as copying the REGEXP; and when the code block is executed, it does so using the pad of the cloned CV. Which makes everything come out all right in the wash. The CV is stored in a new field of the REGEXP, called qr_anoncv. Note that run-time qr//s are still not fixed, e.g. qr/$foo(?{...})/; nor is it yet fixed where the qr// is embedded within another pattern: continuing with the code example from above, my $i = 99; "1" =~ $r[1]; # bare qr: matches: correct! "X99" =~ /X$r[1]/; # embedded qr: matches: whoops, it's still seeing the wrong $i
Diffstat (limited to 't/lib/strict')
-rw-r--r--t/lib/strict/subs8
-rw-r--r--t/lib/strict/vars8
2 files changed, 7 insertions, 9 deletions
diff --git a/t/lib/strict/subs b/t/lib/strict/subs
index e3e401408f..5fd0b03de7 100644
--- a/t/lib/strict/subs
+++ b/t/lib/strict/subs
@@ -378,8 +378,8 @@ Execution of - aborted due to compilation errors.
use strict 'subs';
qr/(?{my $x=foo})/;
EXPECT
-Bareword "foo" not allowed while "strict subs" in use at (re_eval 1) line 1.
-Compilation failed in regexp at - line 3.
+Bareword "foo" not allowed while "strict subs" in use at - line 3.
+Execution of - aborted due to compilation errors.
########
# Regexp compilation errors weren't UTF-8 clean
use strict 'subs';
@@ -387,8 +387,8 @@ use utf8;
use open qw( :utf8 :std );
qr/(?{my $x=fòò})/;
EXPECT
-Bareword "fòò" not allowed while "strict subs" in use at (re_eval 1) line 1.
-Compilation failed in regexp at - line 5.
+Bareword "fòò" not allowed while "strict subs" in use at - line 5.
+Execution of - aborted due to compilation errors.
########
# [perl #27628] strict 'subs' didn't warn on bareword array index
use strict 'subs';
diff --git a/t/lib/strict/vars b/t/lib/strict/vars
index 6e3c1e90f4..c6cb067939 100644
--- a/t/lib/strict/vars
+++ b/t/lib/strict/vars
@@ -517,11 +517,9 @@ Execution of - aborted due to compilation errors.
# [perl #26910] hints not propagated into (?{...})
use strict 'vars';
qr/(?{$foo++})/;
-# XXX temp expect duplicate errors
EXPECT
Global symbol "$foo" requires explicit package name at - line 3.
-Global symbol "$foo" requires explicit package name at (re_eval 1) line 1.
-Compilation failed in regexp at - line 3.
+Execution of - aborted due to compilation errors.
########
# Regex compilation errors weren't UTF-8 clean.
use strict 'vars';
@@ -529,8 +527,8 @@ use utf8;
use open qw( :utf8 :std );
qr/(?{$fòò++})/;
EXPECT
-Global symbol "$fòò" requires explicit package name at (re_eval 1) line 1.
-Compilation failed in regexp at - line 5.
+Global symbol "$fòò" requires explicit package name at - line 5.
+Execution of - aborted due to compilation errors.
########
# [perl #73712] 'Variable is not imported' should be suppressible
$dweck;