Subject: | ProhibitExplicitStdin doesn't quite match what PBP says |
PBP page 216 says
Avoid using *STDIN, unless you really mean it.
That's not the same as 'avoid *STDIN under all circumstances'. Since
perlcritic has no way to detect whether you 'really mean it' or not, the
policy tends to generate false positives. At the least, this would
suggest moving the policy to a lesser severity than level 4.
(I'd also note that the suggested alternative, while (<ARGV>) or while
(<>), is dangerous because it uses two-arg open() internally and so can
be tripped up by the presence of a file called '| echo hello' for
example. So perlcritic is warning about a safe piece of code and
recommending its replacement with something less safe (and that doesn't
accomplish the task of reading from standard input and nowhere else).
What is the perlcritic-approved way to read from standard input?)
I understand that the policy is doing what it says and that if I don't
like it I should turn off the policy. Perl::Critic's engine is not at
fault. This bug report is for three things:
- The policy does not quite match PBP; I think the intention is for
perlcritic out of the box to enforce Damian's guidelines, but he doesn't
prohibit STDIN entirely, just 'unless you really mean it'.
- If the policy is kept as-is, it could be made lower severity.
- The help text printed by perlcritic is not particularly helpful. It
recommends using an unsafe construct (yes, I know Damian does the same).