-
Notifications
You must be signed in to change notification settings - Fork 588
Avoid using $_ when loading the commands from namespaces #2181
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
base: main
Are you sure you want to change the base?
Conversation
f6c8a1f to
91c03a9
Compare
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.
Pull Request Overview
This PR refactors the command-loading loop to avoid using the implicit $_, preventing unintended global variable pollution.
- Replaced a chained
grep/forusing$_with an explicitfor my $pkgloop. - Added an early
next unless _command($pkg)guard. - Updated the hash assignment to use the named
$pkgvariable.
Comments suppressed due to low confidence (3)
lib/Mojolicious/Commands.pm:68
- [nitpick] Consider renaming
$pkgto a more descriptive name like$moduleor$command_classto clarify that it represents a command class.
for my $pkg (find_modules($ns), find_packages($ns)) {
lib/Mojolicious/Commands.pm:67
- [nitpick] Add a comment explaining that this loop avoids using
$_to prevent pollution from upstream code, clarifying the purpose of the refactoring.
for my $ns (@{$self->namespaces}) {
lib/Mojolicious/Commands.pm:71
- Consider adding a test case to verify that command loading no longer pollutes
$_, ensuring this transformation addresses the original issue (#2175).
}
|
Bump, why isn't this merged? Seems like a low-hanging fruit. |
|
Nobody will even look at it before tests passed, |
|
I'm confused. Am I required to take any action here? Did the tests fail? They look like they never ran at all. |
|
No idea what went wrong i'm afraid, and nothing we can do about it. |
|
I rebased to latest main. Seems like workflows await approval now. Maybe that'll fix them. |
|
Most tests passed now. Windows test seems to be failing in other PRs too, regardless of their content. |
Summary
Solution proposed in #2175
Motivation
Polluting
$_can happen deep down in dependencies tree of the loaded command.References
resolves #2175