Show quoted text> I just ran into this with the *very* common idiom of:
> chomp (my $val = <STDIN>);
>
> As for the general rule, in English, it's obvious that parentheses
> should be allowed whenever precedence changes if they're not there.
> Now, how to implement that in your module, I have no idea. I do
wonder
Show quoted text> if B::Deparse would be at all helpful, however. When running perl
from
Show quoted text> the command line as:
> perl -MO=Deparse,-p file.pl
> the results will show all possible parentheses added, allowing us to
see
Show quoted text> exactly what the precedence is.
Thanks for bringing this up again (I had kinda forgotten about it).
One of the philosophical features of Perl::Critic is that it doesn't
actually execute any of the code it analyzes, so B::Deparse isn't
really an option for us (remember that compiling the code causes BEGIN
blocks to be executed).
As you said, the ideal rule is to prohibit parens only when removing
them would change the precedenece of the expression. I think that's
doable, but it's probably more work than I'm willing to do right now.
Instead, I might just come up with some simple exceptions (such as
unary operators like 'chomp') that cover the most common cases.
I'll work on this and try to improve it before the next release.
-Jeff