summaryrefslogtreecommitdiff
path: root/dump.c
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 /dump.c
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 'dump.c')
-rw-r--r--dump.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/dump.c b/dump.c
index 8f2fa766c6..deebf23b0a 100644
--- a/dump.c
+++ b/dump.c
@@ -634,6 +634,7 @@ const struct flag_to_name pmflags_flags_names[] = {
{PMf_RETAINT, ",RETAINT"},
{PMf_EVAL, ",EVAL"},
{PMf_NONDESTRUCT, ",NONDESTRUCT"},
+ {PMf_HAS_CV, ",HAS_CV"},
};
static SV *
@@ -2066,6 +2067,8 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
PTR2UV(r->pprivate));
Perl_dump_indent(aTHX_ level, file, " OFFS = 0x%"UVxf"\n",
PTR2UV(r->offs));
+ Perl_dump_indent(aTHX_ level, file, " QR_ANONCV = 0x%"UVxf"\n",
+ PTR2UV(r->qr_anoncv));
#ifdef PERL_OLD_COPY_ON_WRITE
Perl_dump_indent(aTHX_ level, file, " SAVED_COPY = 0x%"UVxf"\n",
PTR2UV(r->saved_copy));