diff options
author | Father Chrysostomos <sprout@cpan.org> | 2013-08-10 09:49:28 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2013-08-11 07:54:42 -0700 |
commit | 1c75beb82e2bc71836b8b226cb4e976792d1967c (patch) | |
tree | abb0787518fa956de23734503525ef4d1a1868c5 /t/op/magic.t | |
parent | ae7a8a78f1dbd467b63525c5201b8377dc705e7b (diff) | |
download | perl-1c75beb82e2bc71836b8b226cb4e976792d1967c.tar.gz |
Modifying ${^OPEN} changes the value of $^H:
$ ./perl -le 'BEGIN { print $^H; ${^OPEN} = "a\0b"; print $^H}'
256
917760
So changing $^H back should change the value of ${^OPEN} back to undef, right?
$ ./perl -le 'BEGIN { ${^OPEN} = "a\0b"; $^H=256; print ${^OPEN}//"undef"}'
ab
$ ./perl -le 'BEGIN { ${^OPEN} = "a\0b"; $^H=256;}BEGIN{ print ${^OPEN}//"undef"}'
undef
Apparently you have to hop from one BEGIN block to another to see
the changes.
This happens because compile-time hints are stored in PL_hints (which
$^H sets) but ${^OPEN} looks in PL_compiling.cop_hints. Setting
${^OPEN} sets both. The contents of PL_hints are assigned to
PL_compiling.cop_hints at certain points (the start of a BEGIN block
sees the right value because newSTATEOP sets it), but the two are not
always kept in synch.
The smallest fix here is to have $^H set PL_compiling.cop_hints as
well as PL_hints, but the ultimate fix--to come later--is to merge the
two and stop storing hints in two different places.
Diffstat (limited to 't/op/magic.t')
-rw-r--r-- | t/op/magic.t | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/t/op/magic.t b/t/op/magic.t index 7abddbe56a..7a929d0f9a 100644 --- a/t/op/magic.t +++ b/t/op/magic.t @@ -5,7 +5,7 @@ BEGIN { chdir 't' if -d 't'; @INC = '../lib'; require './test.pl'; - plan (tests => 179); + plan (tests => 180); } # Test that defined() returns true for magic variables created on the fly, @@ -634,6 +634,18 @@ fresh_perl_is 'select f; undef *f; ${q/|/}; print STDOUT qq|ok\n|', "ok\n", {}, '[perl #115206] no crash when vivifying $| while *{+select}{IO} is undef'; +# ${^OPEN} and $^H interaction +# Setting ${^OPEN} causes $^H to change, but setting $^H would only some- +# times make ${^OPEN} change, depending on whether it was in the same BEGIN +# block. Don’t test actual values (subject to change); just test for +# consistency. +my @stuff; +eval ' + BEGIN { ${^OPEN} = "a\0b"; $^H = 0; push @stuff, ${^OPEN} } + BEGIN { ${^OPEN} = "a\0b"; $^H = 0 } BEGIN { push @stuff, ${^OPEN} } +1' or die $@; +is $stuff[0], $stuff[1], '$^H modifies ${^OPEN} consistently'; + # ^^^^^^^^^ New tests go here ^^^^^^^^^ |