Open bbrtj opened 1 month ago
It is very dangerous to modify $_
without localization in code that may be used elsewhere. The most common cause of this is a while-readline loop that does not assign to a lexical variable.
A simpler way to "defang" the $_
alias would be: _command(local $_ = $_)
, but this would need a comment to explain the oddity.
Just a thought: since the code inside grep
is loading modules via load_class
it's possibly executing a lot of perl code and it's hard to control the scope of it. I believe it's safer to restrain from $_
usage in this case.
Steps to reproduce the behavior
Loop at line 69 of Mojolicious::Commands encounters an undefined value if the topic variable
$_
is set to undefined in the compilation phase of that command. Example (on a freshly generated app):Note: In the real project case I'm not setting that value explicitly, I'm using
Beam::Wire
at compilation phase which most likely does that one way or another because the observed behavior is the same.Expected behavior
While polluting $_ is obviously erroneous, I believe Commands system should be resistant.
Actual behavior
I get these errors:
Rewriting the Mojolicious::Commands loop to this form fixes the issue for me: