(perl #134193) allow %{^CAPTURE} to work when @{^CAPTURE} comes first
authorTony Cook <tony@develop-help.com>
Thu, 13 Jun 2019 00:05:15 +0000 (10:05 +1000)
committerTony Cook <tony@develop-help.com>
Wed, 19 Jun 2019 04:22:10 +0000 (14:22 +1000)
gv_magicalize() is called when the GV is created, so when the array
was mentioned first, the hash wouldn't reach this code and the magic
wouldn't be added to the hash.

This also fixes a similar problem with (%|@){^CAPTURE_ALL}, though
@{^CAPTURE_ALL} is unused at this point.

ext/Tie-Hash-NamedCapture/t/tiehash.t
gv.c

index 9627540..cca0527 100644 (file)
@@ -3,6 +3,9 @@ use strict;
 
 use Test::More;
 
+# this would break the hash magic setup [perl #134193]
+my ($ca, $c) = ( \@{^CAPTURE_ALL}, \@{^CAPTURE} );
+
 my %hashes = (
     '+' => \%+,
     '-' => \%-,
diff --git a/gv.c b/gv.c
index 46a32dc..2b83680 100644 (file)
--- a/gv.c
+++ b/gv.c
@@ -2032,13 +2032,11 @@ S_gv_magicalize(pTHX_ GV *gv, HV *stash, const char *name, STRLEN len,
                     sv_magic(MUTABLE_SV(av), (SV*)n, PERL_MAGIC_regdata, NULL, 0);
                     SvREADONLY_on(av);
 
-                    if (sv_type == SVt_PVHV || sv_type == SVt_PVGV)
-                        require_tie_mod_s(gv, '-', "Tie::Hash::NamedCapture",0);
+                    require_tie_mod_s(gv, '-', "Tie::Hash::NamedCapture",0);
 
                 } else          /* %{^CAPTURE_ALL} */
                 if (memEQs(name, len, "\003APTURE_ALL")) {
-                    if (sv_type == SVt_PVHV || sv_type == SVt_PVGV)
-                        require_tie_mod_s(gv, '+', "Tie::Hash::NamedCapture",0);
+                    require_tie_mod_s(gv, '+', "Tie::Hash::NamedCapture",0);
                 }
                break;
            case '\005':        /* $^ENCODING */