File Coverage

blib/lib/Perl/Critic/Policy/Bangs/ProhibitBitwiseOperators.pm
Criterion Covered Total %
statement 26 27 96.3
branch 2 2 100.0
condition n/a
subroutine 10 11 90.9
pod 4 5 80.0
total 42 45 93.3


line stmt bran cond sub pod time code
1             package Perl::Critic::Policy::Bangs::ProhibitBitwiseOperators;
2              
3 4     4   3450 use 5.006001;
  4         12  
  4         183  
4 4     4   22 use strict;
  4         7  
  4         112  
5 4     4   20 use warnings;
  4         7  
  4         96  
6 4     4   21 use Readonly;
  4         6  
  4         201  
7              
8 4     4   22 use Perl::Critic::Utils qw{ :severities :classification :data_conversion };
  4         5  
  4         230  
9 4     4   1932 use base 'Perl::Critic::Policy';
  4         9  
  4         1197  
10              
11             our $VERSION = '1.11_02';
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 12     12 0 96347 sub supported_parameters { return () }
21 7     7 1 83 sub default_severity { return $SEVERITY_HIGHEST }
22 0     0 1 0 sub default_themes { return qw( core bugs ) }
23 9     9 1 116626 sub applies_to { return 'PPI::Token::Operator' }
24              
25             #-----------------------------------------------------------------------------
26              
27             my %bitwise_operators = hashify( qw( & | ^ ~ &= |= ^= ) );
28              
29             sub violates {
30 71     71 1 453 my ( $self, $elem, undef ) = @_;
31              
32 71         159 my $content = $elem->content();
33 71 100       327 if ( $bitwise_operators{$content} ) {
34 7         53 return $self->violation( $DESC, qq{$EXPL "$content"}, $elem );
35             }
36 64         116 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-2013 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