File Coverage

blib/lib/Perl/Lint/Policy/RegularExpressions/ProhibitUselessTopic.pm
Criterion Covered Total %
statement 28 28 100.0
branch 8 10 80.0
condition 6 6 100.0
subroutine 6 6 100.0
pod 0 1 0.0
total 48 51 94.1


line stmt bran cond sub pod time code
1             package Perl::Lint::Policy::RegularExpressions::ProhibitUselessTopic;
2 134     134   94541 use strict;
  134         234  
  134         4773  
3 134     134   615 use warnings;
  134         177  
  134         3428  
4 134     134   930 use Perl::Lint::Constants::Type;
  134         163  
  134         84668  
5 134     134   786 use parent "Perl::Lint::Policy";
  134         225  
  134         782  
6              
7             use constant {
8 134         32959 DESC => 'Useless use of $_',
9             EXPL => '$_ should be omitted when matching a regular expression',
10 134     134   8817 };
  134         215  
11              
12             sub evaluate {
13 11     11 0 23 my ($class, $file, $tokens, $src, $args) = @_;
14              
15 11         12 my @violations;
16 11         39 for (my $i = 0, my $token_type; my $token = $tokens->[$i]; $i++) {
17 444         326 $token_type = $token->{type};
18              
19 444 100       853 if ($token_type == SPECIFIC_VALUE) {
20 37 50       49 $token = $tokens->[++$i] or last;
21 37         34 $token_type = $token->{type};
22              
23 37 100 100     73 if ($token_type == REG_OK || $token_type == REG_NOT) {
24 35 50       51 $token = $tokens->[++$i] or last;
25 35         25 $token_type = $token->{type};
26              
27 35 100 100     106 if ($token_type != VAR && $token_type != GLOBAL_VAR) {
28 30         108 push @violations, {
29             filename => $file,
30             line => $token->{line},
31             description => DESC,
32             explanation => EXPL,
33             policy => __PACKAGE__,
34             };
35             }
36             }
37             }
38              
39             }
40              
41 11         38 return \@violations;
42             }
43              
44             1;
45