From 0ff126f3f2b1c0740071936055f14dbc9309f605 Mon Sep 17 00:00:00 2001 From: Aristotle Pagaltzis Date: Sun, 14 Aug 2016 06:42:06 +0200 Subject: [PATCH] stop directly mutating $^H in strict::bits() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This improves the code in two ways: 1. Considering strict::bits is used by B::Deparse and vars.pm as unofficial API, the function having this side effect is arguably a latent bug even if it doesn’t break those callers. 2. It is harder to follow the intended logic when the function modifies $^H itself but also returns a value for the caller to apply to $^H. --- lib/strict.pm | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/strict.pm b/lib/strict.pm index ad31edcacfa6..3091a9bd1deb 100644 --- a/lib/strict.pm +++ b/lib/strict.pm @@ -1,6 +1,6 @@ package strict; -$strict::VERSION = "1.13"; +$strict::VERSION = "1.14"; my ( %bitmask, %explicit_bitmask ); @@ -12,12 +12,15 @@ BEGIN { if __FILE__ !~ ( '(?x) \b '.__PACKAGE__.' \.pmc? \z' ) && __FILE__ =~ ( '(?x) \b (?i:'.__PACKAGE__.') \.pmc? \z' ); + # which strictures are actually in force %bitmask = ( refs => 0x00000002, subs => 0x00000200, vars => 0x00000400, ); + # which strictures have at some point been turned on or off explicitly + # and must therefore not be touched by any subsequent `use VERSION` or `no VERSION` %explicit_bitmask = ( refs => 0x00000020, subs => 0x00000040, @@ -38,12 +41,12 @@ BEGIN { } sub bits { + my $do_explicit = caller eq __PACKAGE__; my $bits = 0; my @wrong; foreach my $s (@_) { if (exists $bitmask{$s}) { - $^H |= $explicit_bitmask{$s}; - + $bits |= $explicit_bitmask{$s} if $do_explicit; $bits |= $bitmask{$s}; } else { @@ -66,7 +69,9 @@ sub unimport { shift; if (@_) { - $^H &= ~&bits; + my $bits = &bits; + $^H &= ~$bits; + $^H |= all_explicit_bits & $bits; } else { $^H &= ~all_bits; @@ -75,6 +80,7 @@ sub unimport { } 1; + __END__ =head1 NAME