-
Notifications
You must be signed in to change notification settings - Fork 576
Simplify strict.pm #22848
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify strict.pm #22848
Conversation
Needs a version bump in lib/strict.pm. |
@jkeenan Yes, but that’s the least of the problems. Turns out |
(OTOH this has unearthed the fact that some of the use of |
new docs are always good |
497a220
to
1766feb
Compare
lib/strict.pm
Outdated
@@ -59,14 +61,15 @@ sub bits { | |||
|
|||
sub import { | |||
shift; | |||
$^H |= @_ ? &bits : all_bits | all_explicit_bits; | |||
$^H |= @_ ? &bits | $explicit_bits : all_bits | all_explicit_bits; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&bits | $explicit_bits
relies on left-to-right evaluation in |
since &bits
resets the value of $explicit_bits
. Does perl guarantee left-to-right evaluation in non-shortcutting operators?
Perhaps an alternative: diff --git i/lib/strict.pm w/lib/strict.pm
index ad31edcacf..0579fce7d2 100644
--- i/lib/strict.pm
+++ w/lib/strict.pm
@@ -42,8 +42,7 @@ sub bits {
my @wrong;
foreach my $s (@_) {
if (exists $bitmask{$s}) {
- $^H |= $explicit_bitmask{$s};
-
+ $bits |= $explicit_bitmask{$s};
$bits |= $bitmask{$s};
}
else {
@@ -66,7 +65,9 @@ sub unimport {
shift;
if (@_) {
- $^H &= ~&bits;
+ my $bits = &bits;
+ $^H &= ~$bits;
+ $^H |= all_explicit_bits & $bits;
}
else {
$^H &= ~all_bits; |
41e3117
to
8bf9adf
Compare
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.
strict.pm is slightly confusing to follow. Restructuring it to make it more legible makes it more apparent that there are some optimizations to be had, which make it no harder to understand, so I’ve taken that opportunity as well.