« Perl/Lint/Policy/Modules/RequireFilenameMatchesPackage.pm
↑ Summary
Perl/Lint/Policy/InputOutput/ProhibitBarewordFileHandles.pm »
| 1 | package Perl::Lint::Policy::RegularExpressions::ProhibitSingleCharAlternation; | ||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use Perl::Lint::Constants::Type; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 3 | ▶ | use parent "Perl::Lint::Policy"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 3 | ▶ | use constant { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 3 | DESC => 'Use [%s] instead of %s', | |||||||||
| 9 | EXPL => [265], | ||||||||||
| 10 | 3 | }; | |||||||||
| 11 | |||||||||||
| 12 | 2 | ▶ | sub evaluate { | ||||||||
|
Subroutine
evaluate: called CC=10 SCAR=34.7
Pod
undocumented
| |||||||||||
| 13 | 2 | my ($class, $file, $tokens, $src, $args) = @_; | |||||||||
| 14 | |||||||||||
| 15 | 2 | my @violations; | |||||||||
| 16 | 2 | ▶ | for (my $i = 0, my $token_type, my $token_data; my $token = $tokens->[$i]; $i++) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | 51 | $token_type = $token->{type}; | |||||||||
| 18 | 51 | $token_data = $token->{data}; | |||||||||
| 19 | |||||||||||
| 20 | 51 | ▶ | if ($token_type == REG_EXP) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | 2 | ▶ | if (my @groups = $token_data =~ /\( \?\: \s* (.+?) \s* \)/gx) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 0 | TRAVERSE_REGEX: for my $group (@groups) { | |||||||||
| 23 | 0 | ▶ | if ($group =~ /\A \w \Z/x) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | 0 | last; | |||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 0 | my @singles; | |||||||||
| 28 | 0 | for my $part (split /\s* \| \s*/x, $group) { | |||||||||
| 29 | 0 | ▶ | if ($part !~ /\A \w+ \Z/x) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 0 | last TRAVERSE_REGEX; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 0 | ▶ | if (length $part == 1) { # if single char | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 0 | push @singles, $part; | |||||||||
| 35 | } | ||||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | 0 | ▶ | if (scalar @singles > 1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | push @violations, { | ||||||||||
| 40 | filename => $file, | ||||||||||
| 41 | line => $token->{line}, | ||||||||||
| 42 | 0 | description => sprintf( | |||||||||
| 43 | DESC, | ||||||||||
| 44 | join('', @singles), | ||||||||||
| 45 | join('|', @singles), | ||||||||||
| 46 | ), | ||||||||||
| 47 | explanation => EXPL, | ||||||||||
| 48 | policy => __PACKAGE__, | ||||||||||
| 49 | }; | ||||||||||
| 50 | } | ||||||||||
| 51 | } | ||||||||||
| 52 | } | ||||||||||
| 53 | } | ||||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 2 | return \@violations; | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 3 | 1; | |||||||||
| 60 | |||||||||||