File Coverage

blib/lib/Perl/Critic/Policy/OTRS/ProhibitLowPrecedenceOps.pm
Criterion Covered Total %
statement 23 23 100.0
branch 2 2 100.0
condition n/a
subroutine 10 10 100.0
pod 5 5 100.0
total 40 40 100.0


line stmt bran cond sub pod time code
1             package Perl::Critic::Policy::OTRS::ProhibitLowPrecedenceOps;
2              
3             # ABSTRACT: Do not use "not", "and" and other low precedence operators
4              
5 24     24   19330 use strict;
  24         69  
  24         749  
6 24     24   133 use warnings;
  24         53  
  24         812  
7              
8 24     24   144 use Perl::Critic::Utils qw{ :severities :classification :ppi };
  24         73  
  24         1374  
9 24     24   8823 use base 'Perl::Critic::Policy';
  24         77  
  24         2585  
10              
11 24     24   169 use Readonly;
  24         61  
  24         5533  
12              
13             our $VERSION = '0.03';
14              
15             Readonly::Scalar my $DESC => q{Use of low precedence operators is not allowed};
16             Readonly::Scalar my $EXPL => q{Replace low precedence operators with the high precedence substitutes};
17              
18             my %lowprecedence = (
19             not => '!',
20             and => '&&',
21             or => '||',
22             );
23              
24 12     12 1 28175 sub supported_parameters { return; }
25 3     3 1 43 sub default_severity { return $SEVERITY_HIGHEST; }
26 1     1 1 722 sub default_themes { return qw( otrs otrs_lt_3_3 ) }
27 4     4 1 307179 sub applies_to { return 'PPI::Token::Operator' }
28              
29             sub violates {
30 15     15 1 1016 my ( $self, $elem ) = @_;
31              
32 15 100       50 return if !grep{ $elem eq $_ }keys %lowprecedence;
  45         453  
33 2         36 return $self->violation( $DESC, $EXPL, $elem );
34             }
35              
36             1;
37              
38             __END__
39              
40             =pod
41              
42             =encoding UTF-8
43              
44             =head1 NAME
45              
46             Perl::Critic::Policy::OTRS::ProhibitLowPrecedenceOps - Do not use "not", "and" and other low precedence operators
47              
48             =head1 VERSION
49              
50             version 0.09
51              
52             =head1 METHODS
53              
54             =head2 supported_parameters
55              
56             There are no supported parameters.
57              
58             =head1 AUTHOR
59              
60             Renee Baecker <info@perl-services.de>
61              
62             =head1 COPYRIGHT AND LICENSE
63              
64             This software is Copyright (c) 2013 by Renee Baecker.
65              
66             This is free software, licensed under:
67              
68             The Artistic License 2.0 (GPL Compatible)
69              
70             =cut