This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Refactor newXS’s autouse logic
authorFather Chrysostomos <sprout@cpan.org>
Mon, 21 Nov 2011 22:14:36 +0000 (14:14 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 22 Nov 2011 00:24:45 +0000 (16:24 -0800)
Putting inside the if() condition allows me to add an || in the
next commit.

op.c

diff --git a/op.c b/op.c
index 257e221..1dcfcad 100644 (file)
--- a/op.c
+++ b/op.c
@@ -7014,19 +7014,16 @@ Perl_newXS_len_flags(pTHX_ const char *name, STRLEN len,
             }
             else if (CvROOT(cv) || CvXSUB(cv) || GvASSUMECV(gv)) {
                 /* already defined (or promised) */
-                if (ckWARN(WARN_REDEFINE)) {
+               const char *redefined_name;
+                if (ckWARN(WARN_REDEFINE)
+                    && !(
+                           CvGV(cv) && GvSTASH(CvGV(cv))
+                        && HvNAMELEN(GvSTASH(CvGV(cv))) == 7
+                        && (redefined_name = HvNAME(GvSTASH(CvGV(cv))),
+                            strEQ(redefined_name, "autouse"))
+                        )
+               ) {
                     const line_t oldline = CopLINE(PL_curcop);
-                    GV * const gvcv = CvGV(cv);
-                    if (gvcv) {
-                        HV * const stash = GvSTASH(gvcv);
-                        if (stash) {
-                            const char *redefined_name = HvNAME_get(stash);
-                            if ( redefined_name &&
-                                 strEQ(redefined_name,"autouse") ) {
-                                goto nope;
-                            }
-                        }
-                    }
                     if (PL_parser && PL_parser->copline != NOLINE)
                         CopLINE_set(PL_curcop, PL_parser->copline);
                     Perl_warner(aTHX_ packWARN(WARN_REDEFINE),
@@ -7039,7 +7036,6 @@ Perl_newXS_len_flags(pTHX_ const char *name, STRLEN len,
                                       ));
                     CopLINE_set(PL_curcop, oldline);
                 }
-             nope:
                 SvREFCNT_dec(cv);
                 cv = NULL;
             }