NAME

Perl::Critic::Policy::ValuesAndExpressions::ConstantBeforeLt - disallow bareword before <

DESCRIPTION

This policy is part of the Perl-Critic-Pulp addon. It prohibits a bareword before a < to keep you out of trouble on Perl prior to 5.10.0, where such an < is interpreted as the start of a <..> readline or glob, instead of a less-than. On that basis this policy is under the bugs theme.

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 on own constant

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, whichever you think is less awful.

If you've got an explicit use of Perl 5.10 or higher the policy is skipped, since there's no problem there.

use 5.010;
DBL_MANT_DIG < 10    # ok in perl 5.10

If you only use Perl 5.10 but don't bother putting that in your sources then disable this policy in your .perlcriticrc file in the usual way

[-ValuesAndExpressions::ConstantBeforeLt]

OTHER NOTES

Bareword file handles might be misinterpreted by this policy as constants, but in practice a "<" doesn't get used with anything taking a bare filehandle.

PPI version 1.203 doesn't parse v-strings like use v5.10.0, so that won't be recognised as a 5.10 to suppress this policy. Use use 5.010 style instead.

SEE ALSO

Perl::Critic

COPYRIGHT

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.