Perl::Critic::Policy::ValuesAndExpressions::ConstantBeforeLt - disallow bareword before <
This policy is part of the Perl::Critic::Pulp addon. It prohibits a bareword before a < to keep you out of trouble with autoloaded or unprototyped constant subs since a < in that case is interpreted as the start of a <..> glob or readline, instead of a less-than. This policy is under the bugs theme (see "POLICY THEMES" in Perl::Critic).
<
<..>
bugs
use POSIX; DBL_MANT_DIG < 32 # bad, perl 5.8 thinks <> func <*.c> # ok, actual glob time < 2e9 # ok, builtins parse ok use constant FOO => 16; FOO < 32 # ok, your own const
The fix for something like DBL_MANT_DIG < 10 is parens either around or after, like (DBL_MANT_DIG) < 10 or DBL_MANT_DIG() < 10. Probably the latter is less worse, emphasising it's really a sub.
DBL_MANT_DIG < 10
(DBL_MANT_DIG) < 10
DBL_MANT_DIG() < 10
The key issue is whether the constant sub in question is defined and has a prototype at the time the code is compiled. ConstantBeforeLt makes the pessimistic assumption that anything except use constant in your own file shouldn't be relied on.
use constant
In practice the most likely problems are with the POSIX module constants of Perl 5.8.x and earlier, since they were unprototyped. And the default code generated by h2xs (as of Perl 5.10.0) is autoloaded unprototyped constants, so any module using the bare output of that suffers.
POSIX
h2xs
If you're confident the modules you use don't play tricks with their constants (including only using POSIX on Perl 5.10.0 or higher) then you might find ConstantBeforeLt too pessimistic. It normally triggers rather rarely anyway, but as always if you want you can disable it altogether in your .perlcriticrc file,
[-ValuesAndExpressions::ConstantBeforeLt]
Bareword file handles might be misinterpreted by this policy as constants, but in practice "<" doesn't get used with anything taking a bare filehandle.
A constant used before it's defined, like
if (FOO < 123) { ... } # bad ... use constant FOO => 456;
is reported by ConstantBeforeLt since it might be an imported constant sub, even if it's more likely to be a simple mis-ordering (which use strict picks up anyway).
use strict
Perl::Critic::Pulp, Perl::Critic
Copyright 2008 Kevin Ryde
Perl-Critic-Pulp is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Perl-Critic-Pulp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Perl-Critic-Pulp. If not, see http://www.gnu.org/licenses.
To install Perl::Critic::Pulp, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Perl::Critic::Pulp
CPAN shell
perl -MCPAN -e shell install Perl::Critic::Pulp
For more information on module installation, please visit the detailed CPAN module installation guide.