line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Critic::Policy::Bangs::ProhibitBitwiseOperators; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
2734
|
use 5.006001; |
|
5
|
|
|
|
|
19
|
|
4
|
5
|
|
|
5
|
|
26
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
79
|
|
5
|
5
|
|
|
5
|
|
20
|
use warnings; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
95
|
|
6
|
5
|
|
|
5
|
|
18
|
use Readonly; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
212
|
|
7
|
|
|
|
|
|
|
|
8
|
5
|
|
|
5
|
|
25
|
use Perl::Critic::Utils qw{ :severities :classification :data_conversion }; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
210
|
|
9
|
5
|
|
|
5
|
|
1622
|
use base 'Perl::Critic::Policy'; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
999
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '1.12'; |
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
|
75865
|
sub supported_parameters { return () } |
21
|
7
|
|
|
7
|
1
|
88
|
sub default_severity { return $SEVERITY_HIGHEST } |
22
|
0
|
|
|
0
|
1
|
0
|
sub default_themes { return qw( bangs bugs ) } |
23
|
10
|
|
|
10
|
1
|
116470
|
sub applies_to { return 'PPI::Token::Operator' } |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my %bitwise_operators = hashify( qw( & | ^ ~ &= |= ^= ) ); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub violates { |
30
|
72
|
|
|
72
|
1
|
472
|
my ( $self, $elem, undef ) = @_; |
31
|
|
|
|
|
|
|
|
32
|
72
|
|
|
|
|
159
|
my $content = $elem->content(); |
33
|
72
|
100
|
|
|
|
323
|
if ( $bitwise_operators{$content} ) { |
34
|
7
|
|
|
|
|
49
|
return $self->violation( $DESC, qq{$EXPL "$content"}, $elem ); |
35
|
|
|
|
|
|
|
} |
36
|
65
|
|
|
|
|
128
|
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 |