From 22f05786af0b7f963440e47908cd5f35cf074c12 Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Thu, 13 Jun 2019 10:05:15 +1000 Subject: [PATCH] (perl #134193) allow %{^CAPTURE} to work when @{^CAPTURE} comes first MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. Signed-off-by: Petr Písař --- ext/Tie-Hash-NamedCapture/t/tiehash.t | 3 +++ gv.c | 6 ++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ext/Tie-Hash-NamedCapture/t/tiehash.t b/ext/Tie-Hash-NamedCapture/t/tiehash.t index 962754085f..cca05278f4 100644 --- a/ext/Tie-Hash-NamedCapture/t/tiehash.t +++ b/ext/Tie-Hash-NamedCapture/t/tiehash.t @@ -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 46a32dcc20..2b83680898 100644 --- 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 */ -- 2.20.1