GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Perl::Critic::Policy::ValuesAndExpressions::ConstantBeforeLt(3) User Contributed Perl Documentation Perl::Critic::Policy::ValuesAndExpressions::ConstantBeforeLt(3)

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

This policy is part of the "Perl::Critic::Pulp" add-on. 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).

    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

    sub BAR () { 64 }
    BAR < 32            # ok, your own prototyped sub

The fix for something like "DBL_MANT_DIG < 10" is parens either around or after, like

    (DBL_MANT_DIG) < 10  # ok
    DBL_MANT_DIG() < 10  # ok

whichever you think is less worse. The latter emphasises it's really a sub.

The key 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" and prototyped subs in your own file shouldn't be relied on.

In practice the most likely problems are with the "POSIX" module constants of Perl 5.8.x and earlier, since they were unprototyped. The default code generated by "h2xs" (as of Perl 5.10.0) is similar autoloaded unprototyped constants so modules using the bare output of that suffer too.

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 you can always disable it altogether in your .perlcriticrc file (see "CONFIGURATION" in Perl::Critic),

    [-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 much more likely to be a simple mis-ordering, which "use strict" picks up anyway when it runs.

Perl::Critic::Pulp, Perl::Critic

http://user42.tuxfamily.org/perl-critic-pulp/index.html

Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2021 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/>.

2021-02-27 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.