Perl::Critic::Policy::Bangs::ProhibitBitwiseOperators - Bitwise operators are usually accidentally used instead of logical boolean operators.


Perl-Critic-Bangs documentation Contained in the Perl-Critic-Bangs distribution.

Index


Code Index:

NAME

Top

Perl::Critic::Policy::Bangs::ProhibitBitwiseOperators - Bitwise operators are usually accidentally used instead of logical boolean operators.

AFFILIATION

Top

This Policy is part of the Perl::Critic::Bangs distribution.

DESCRIPTION

Top

Bitwise operators are usually accidentally used instead of logical boolean operators. Instead of writing $a || $b, people will often write $a | $b, which is not correct.

CONFIGURATION

Top

This policy cannot be configured.

AUTHOR

Top

Mike O'Regan <moregan@stresscafe.com>

COPYRIGHT

Top


Perl-Critic-Bangs documentation Contained in the Perl-Critic-Bangs distribution.

package Perl::Critic::Policy::Bangs::ProhibitBitwiseOperators;

use 5.006001;
use strict;
use warnings;
use Readonly;

use Perl::Critic::Utils qw{ :severities :classification :data_conversion };
use base 'Perl::Critic::Policy';

our $VERSION = '1.08';

#-----------------------------------------------------------------------------

Readonly::Scalar my $DESC => q{Use of bitwise operator};
Readonly::Scalar my $EXPL => q{Use of bitwise operator};

#-----------------------------------------------------------------------------

sub supported_parameters { return ()                     }
sub default_severity     { return $SEVERITY_HIGHEST      }
sub default_themes       { return qw( core bugs )        }
sub applies_to           { return 'PPI::Token::Operator' }

#-----------------------------------------------------------------------------

my %bitwise_operators = hashify( qw( & | ^ ~ &= |= ^= ) );

sub violates {
    my ( $self, $elem, undef ) = @_;

    my $content = $elem->content();
    if ( $bitwise_operators{$content} ) {
        return $self->violation( $DESC, qq{$EXPL "$content"}, $elem );
    }
    return;    #ok!
}

1;

#---------------------------------------------------------------------------