NAME
Perl::Critic::Policy::ValuesAndExpressions::NotWithCompare - logical not used as a value
DESCRIPTION
This policy is part of the Perl::Critic::Pulp addon. It picks up some cases of logical not !
used with a comparison, like
! $x =~ /^[123]/ # bad
! $x + $y >= $z # bad
In each case Perl parses this as (!$x)
, not a negated comparison. Usually writing something like that is an oversight or mistake, and for that reason this policy is under the "bugs" theme (see "POLICY THEMES" in Perl::Critic).
As a special case, !
is on both sides of ==
or !=
is allowed, since it's a reasonable way to test for the same (or different) as booleans.
!$x == !$y # ok
!$x != !$y # ok
LIMITATIONS
User functions called without parentheses are assumed to be the usual varargs style, but a prototype can mean that's not true, letting a bad !
-with-compare expression go undetected. Constant subs created with use constant
(or sub FOO () {...}
) in the file under test are recognised, hopefully anything else too weird is rare.
SEE ALSO
Perl::Critic::Pulp, Perl::Critic
HOME PAGE
http://www.geocities.com/user42_kevin/perl-critic-pulp/index.html
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.