File Coverage

blib/lib/Perl/Critic/Policy/Bangs/ProhibitBitwiseOperators.pm
Criterion Covered Total %
statement 25 26 96.1
branch 2 2 100.0
condition n/a
subroutine 10 11 90.9
pod 4 5 80.0
total 41 44 93.1


line stmt bran cond sub pod time code
1             package Perl::Critic::Policy::Bangs::ProhibitBitwiseOperators;
2              
3 4     4   1974 use 5.006001;
  4         9  
4 4     4   11 use strict;
  4         16  
  4         70  
5 4     4   10 use warnings;
  4         4  
  4         70  
6 4     4   10 use Readonly;
  4         4  
  4         152  
7              
8 4     4   14 use Perl::Critic::Utils qw{ :severities :classification :data_conversion };
  4         4  
  4         161  
9 4     4   974 use base 'Perl::Critic::Policy';
  4         5  
  4         742  
10              
11             our $VERSION = '1.11_03';
12              
13             #-----------------------------------------------------------------------------
14              
15             Readonly::Scalar my $DESC => q{Use of bitwise operator};
16             Readonly::Scalar my $EXPL => q{Use of bitwise operator};
17              
18             #-----------------------------------------------------------------------------
19              
20 13     13 0 50518 sub supported_parameters { return () }
21 7     7 1 45 sub default_severity { return $SEVERITY_HIGHEST }
22 0     0 1 0 sub default_themes { return qw( bangs bugs ) }
23 10     10 1 61984 sub applies_to { return 'PPI::Token::Operator' }
24              
25             #-----------------------------------------------------------------------------
26              
27             my %bitwise_operators = hashify( qw( & | ^ ~ &= |= ^= ) );
28              
29             sub violates {
30 72     72 1 274 my ( $self, $elem, undef ) = @_;
31              
32 72         87 my $content = $elem->content();
33 72 100       181 if ( $bitwise_operators{$content} ) {
34 7         30 return $self->violation( $DESC, qq{$EXPL "$content"}, $elem );
35             }
36 65         63 return; #ok!
37             }
38              
39             1;
40              
41             __END__
42             =pod
43              
44             =head1 NAME
45              
46             Perl::Critic::Policy::Bangs::ProhibitBitwiseOperators - Bitwise operators are usually accidentally used instead of logical boolean operators.
47              
48             =head1 AFFILIATION
49              
50             This Policy is part of the L<Perl::Critic::Bangs> distribution.
51              
52             =head1 DESCRIPTION
53              
54             Bitwise operators are usually accidentally used instead of logical
55             boolean operators. Instead of writing C<$a || $b>, people will often
56             write C<$a | $b>, which is not correct.
57              
58             =head1 CONFIGURATION
59              
60             This policy cannot be configured.
61              
62             =head1 AUTHOR
63              
64             Mike O'Regan <moregan@stresscafe.com>
65              
66             =head1 COPYRIGHT
67              
68             Copyright (C) 2006-2017 Andy Lester and Mike O'Regan
69              
70             This library is free software; you can redistribute it and/or modify
71             it under the terms of the Artistic License 2.0.
72              
73             =cut