File Coverage

blib/lib/Perl/Lint/Policy/RegularExpressions/ProhibitUnusualDelimiters.pm
Criterion Covered Total %
statement 30 30 100.0
branch 7 8 87.5
condition 23 24 95.8
subroutine 6 6 100.0
pod 0 1 0.0
total 66 69 95.6


line stmt bran cond sub pod time code
1             package Perl::Lint::Policy::RegularExpressions::ProhibitUnusualDelimiters;
2 134     134   99129 use strict;
  134         326  
  134         5135  
3 134     134   624 use warnings;
  134         252  
  134         3509  
4 134     134   937 use Perl::Lint::Constants::Type;
  134         232  
  134         87237  
5 134     134   871 use parent "Perl::Lint::Policy";
  134         223  
  134         826  
6              
7             use constant {
8 134         35892 DESC => 'Use only "//" or "{}" to delimit regexps',
9             EXPL => [246],
10 134     134   8979 };
  134         228  
11              
12             sub evaluate {
13 6     6 0 13 my ($class, $file, $tokens, $src, $args) = @_;
14              
15 6         18 my $does_allow_all_brackets = $args->{prohibit_unusual_delimiters}->{allow_all_brackets};
16              
17 6         9 my @violations;
18 6         29 for (my $i = 0; my $token = $tokens->[$i]; $i++) {
19 196         161 my $token_type = $token->{type};
20 196         152 my $token_data = $token->{data};
21              
22 196 100 100     698 if (
      100        
      100        
23             $token_type == REG_DELIM &&
24             $token_data ne '{' &&
25             $token_data ne '}' &&
26             $token_data ne '/'
27             ) {
28 37 100       52 if ($does_allow_all_brackets) {
29 15 50 100     94 if (
      100        
      100        
      100        
      66        
30             $token_data eq '(' || $token_data eq ')' ||
31             $token_data eq '[' || $token_data eq ']' ||
32             $token_data eq '<' || $token_data eq '>'
33             ) {
34 15         31 next;
35             }
36             }
37              
38 22         59 push @violations, {
39             filename => $file,
40             line => $token->{line},
41             description => DESC,
42             explanation => EXPL,
43             policy => __PACKAGE__,
44             };
45              
46 22         41 for ($i++; my $token = $tokens->[$i]; $i++) {
47 80         63 my $token_type = $token->{type};
48 80 100       167 last if $token_type == SEMI_COLON;
49             }
50             }
51             }
52              
53 6         26 return \@violations;
54             }
55              
56             1;
57