This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
pad.c:pad_findmy_pvn: Skip ‘our’ hack for subs
authorFather Chrysostomos <sprout@cpan.org>
Wed, 27 Aug 2014 06:26:28 +0000 (23:26 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 28 Aug 2014 20:04:17 +0000 (13:04 -0700)
There is a hack that allows an ‘our’ variable to be found in the pad
in the statement in which it is declared, to avoid a warning (since
the fallback would be to look up the very same variable in the current
package anyway).

Since the warning this hack avoids doesn’t apply to subroutines, we
can just skip it for subroutine lookup.

pad.c

diff --git a/pad.c b/pad.c
index 1c06f2f..271a9d8 100644 (file)
--- a/pad.c
+++ b/pad.c
@@ -966,6 +966,10 @@ Perl_pad_findmy_pvn(pTHX_ const char *namepv, STRLEN namelen, U32 flags)
     if ((PADOFFSET)offset != NOT_IN_PAD) 
        return offset;
 
     if ((PADOFFSET)offset != NOT_IN_PAD) 
        return offset;
 
+    /* Skip the ‘our’ hack for subroutines, as the warning does not apply.
+     */
+    if (*namepv == '&') return NOT_IN_PAD;
+
     /* look for an our that's being introduced; this allows
      *    our $foo = 0 unless defined $foo;
      * to not give a warning. (Yes, this is a hack) */
     /* look for an our that's being introduced; this allows
      *    our $foo = 0 unless defined $foo;
      * to not give a warning. (Yes, this is a hack) */