This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Use the same outside logic for mysubs and formats
authorFather Chrysostomos <sprout@cpan.org>
Fri, 7 Sep 2012 03:32:47 +0000 (20:32 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 16 Sep 2012 05:45:08 +0000 (22:45 -0700)
By using find_runcv_where both for formats and my subs nested in inner
clonable subs, we can simplify the code.

It happens to make this work ($x is visible):

use 5.01;
sub not_lexical8 {
  my sub foo;
  foo();
  sub not_lexical9 {
    my sub bar {
      my $x = 'khaki car keys for the khaki car';
      not_lexical8();
      sub foo { warn $x }
    }
    bar()
  }
}
not_lexical9();

This is definitely iffy code, but if making it work makes the imple-
mentation simpler, so why not?

pad.c
t/cmd/lexsub.t

diff --git a/pad.c b/pad.c
index 03cb555..85aeea5 100644 (file)
--- a/pad.c
+++ b/pad.c
@@ -1985,18 +1985,8 @@ S_cv_clone_pad(pTHX_ CV *proto, CV *cv, CV *outside)
      */
 
     if (!outside) {
-      if (SvTYPE(proto) == SVt_PVCV)
-      {
+      if (CvWEAKOUTSIDE(proto))
        outside = find_runcv(NULL);
-       if (!CvANON(proto)) {
-           if (!CvPADLIST(outside) ||
-               CvPADLIST(outside)->xpadl_id != protopadlist->xpadl_outid)
-               outside = CvOUTSIDE(proto);
-           if (!CvPADLIST(outside) ||
-               CvPADLIST(outside)->xpadl_id != protopadlist->xpadl_outid)
-               outside = NULL;
-       }
-      }
       else {
        outside = CvOUTSIDE(proto);
        if ((CvCLONE(outside) && ! CvCLONED(outside))
index 7f6df17..f982a0e 100644 (file)
@@ -8,7 +8,7 @@ BEGIN {
     *bar::like = *like;
 }
 no warnings 'deprecated';
-plan 117;
+plan 118;
 
 # -------------------- our -------------------- #
 
@@ -528,6 +528,22 @@ sub make_anon_with_my_sub{
   is $@, "Undefined subroutine &x called at $f line $l.\n",
          'Vivified sub is correctly named';
 }
+sub not_lexical10 {
+  my sub foo;
+  foo();
+  sub not_lexical11 {
+    my sub bar {
+      my $x = 'khaki car keys for the khaki car';
+      not_lexical10();
+      sub foo {
+       is $x, 'khaki car keys for the khaki car',
+       'mysubs in inner clonables use the running clone of their CvOUTSIDE'
+      }
+    }
+    bar()
+  }
+}
+not_lexical11();
 
 # -------------------- Interactions (and misc tests) -------------------- #