Skip to content

Commit 41e3117

Browse files
committed
stop directly mutating $^H in strict::bits()
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.
1 parent d774dbe commit 41e3117

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/strict.pm

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package strict;
22

3-
$strict::VERSION = "1.13";
3+
$strict::VERSION = "1.14";
44

55
my ( %bitmask, %explicit_bitmask );
66

@@ -12,12 +12,15 @@ BEGIN {
1212
if __FILE__ !~ ( '(?x) \b '.__PACKAGE__.' \.pmc? \z' )
1313
&& __FILE__ =~ ( '(?x) \b (?i:'.__PACKAGE__.') \.pmc? \z' );
1414

15+
# which strictures are actually in force
1516
%bitmask = (
1617
refs => 0x00000002,
1718
subs => 0x00000200,
1819
vars => 0x00000400,
1920
);
2021

22+
# which strictures have at some point been turned on or off explicitly
23+
# and must therefore not be touched by any subsequent `use VERSION` or `no VERSION`
2124
%explicit_bitmask = (
2225
refs => 0x00000020,
2326
subs => 0x00000040,
@@ -38,12 +41,12 @@ BEGIN {
3841
}
3942

4043
sub bits {
44+
my $do_explicit = caller eq __PACKAGE__;
4145
my $bits = 0;
4246
my @wrong;
4347
foreach my $s (@_) {
4448
if (exists $bitmask{$s}) {
45-
$^H |= $explicit_bitmask{$s};
46-
49+
$bits |= $explicit_bitmask{$s} if $do_explicit;
4750
$bits |= $bitmask{$s};
4851
}
4952
else {
@@ -67,6 +70,7 @@ sub unimport {
6770

6871
if (@_) {
6972
$^H &= ~&bits;
73+
$^H |= all_explicit_bits & $bits;
7074
}
7175
else {
7276
$^H &= ~all_bits;
@@ -75,6 +79,7 @@ sub unimport {
7579
}
7680

7781
1;
82+
7883
__END__
7984
8085
=head1 NAME

0 commit comments

Comments
 (0)