diff options
author | Father Chrysostomos <sprout@cpan.org> | 2012-08-05 01:05:45 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2012-08-05 16:02:01 -0700 |
commit | f32c7e864b6210c7dabe6a78f842c37aa73c56c3 (patch) | |
tree | b6a222fda29c83ac85ef9cdd7a423c31907b3578 /t | |
parent | bb02a38febc60a289c616282d720015be97842a4 (diff) | |
download | perl-f32c7e864b6210c7dabe6a78f842c37aa73c56c3.tar.gz |
Recursive formats and closures in formats.
Formats called recursively were using the same set of lexicals, so the
inner call would stomp on the outer calls vars, usually clearing them
when exiting.
Previous commits prepared a CvDEPTH field for formats. This commit
sets it in P(USH|OP)FORMAT and pushes a new pad in enterwrite.
This also allows closures to work properly in formats. Formerly they
caused assertion failures in cv_clone. Now cv_clone’s assumptions
about CvDEPTH on CvOUTSIDE and find_runcv are met when subs are embed-
ded in formats.
Diffstat (limited to 't')
-rw-r--r-- | t/comp/form_scope.t | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/t/comp/form_scope.t b/t/comp/form_scope.t index f10637fd54..4a46796fb2 100644 --- a/t/comp/form_scope.t +++ b/t/comp/form_scope.t @@ -1,6 +1,6 @@ #!./perl -print "1..10\n"; +print "1..13\n"; # Tests bug #22977. Test case from Dave Mitchell. sub f ($); @@ -118,18 +118,27 @@ undef &x; print "ok 9 - closure var not available when outer sub is undefined\n"; } -format start_subparse::assertion = -@ -sub { } +format STDOUT7 = +@<<<<<<<<<<<<<<<<<<<<<<<<<<< +do { my $x = "ok 10 - closure inside format"; sub { $x }->() } . -# survived; no "print ok" necessary +*STDOUT = *STDOUT7{FORMAT}; +write; + +$testn = 12; +format STDOUT8 = +@<<<< - recursive formats +do { my $t = "ok " . $testn--; write if $t =~ 12; $t} +. +*STDOUT = *STDOUT8{FORMAT}; +write; # This is a variation of bug #22977, which crashes or fails an assertion # up to 5.16. # Keep this test last if you want test numbers to be sane. BEGIN { \&END } END { - my $test = "ok 10"; + my $test = "ok 13"; *STDOUT = *STDOUT5{FORMAT}; write; format STDOUT5 = |