« Perl/Lint/Policy/BuiltinFunctions/RequireGlobFunction.pm
↑ Summary
Perl/Lint/Policy/RegularExpressions/ProhibitSingleCharAlternation.pm »
| 1 | package Perl::Lint::Policy::Modules::RequireFilenameMatchesPackage; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Perl::Lint::Constants::Type; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use parent "Perl::Lint::Policy"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | DESC => 'Package declaration must match filename', | |||||||||||||||||||||||||||||||||||||||||
| 9 | EXPL => 'Correct the filename or package statement', | ||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 26 | ▶ | sub evaluate { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
evaluate: called CC=27 SCAR=33.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 26 | my ($class, $realfile, $tokens, $src, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 26 | ▶ | if ($src =~ /\A#!/) { # for exempt | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | return []; | |||||||||||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | # Determine the filename with considering directive | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 25 | my $file; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 25 | my @src_rows = split /\r?\n/, $src; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 25 | my $row = 0; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 25 | my $directive_declared_row = 0; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 25 | for my $src_row (@src_rows) { | |||||||||||||||||||||||||||||||||||||||||
| 25 | 101 | $row++; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 101 | ▶ | if ($src_row =~ /\A#line\s\d+\s(.+)\Z/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 9 | ▶ | if ($file) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | return [{ | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | filename => $realfile, | |||||||||||||||||||||||||||||||||||||||||
| 30 | line => $row, | ||||||||||||||||||||||||||||||||||||||||||
| 31 | description => DESC, | ||||||||||||||||||||||||||||||||||||||||||
| 32 | explanation => EXPL, | ||||||||||||||||||||||||||||||||||||||||||
| 33 | policy => __PACKAGE__, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | }]; | ||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 8 | ($file = $1) =~ s/['"]//g; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 8 | $directive_declared_row = $row; | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 24 | ▶ | $file ||= $realfile; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$file ||= $realfile
MC/DC0%0/2
$file ||= $realfile
$file
$realfile
Truth table66%2/3
A ||= B
A= $fileB= $realfile
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 24 | my @violations; | |||||||||||||||||||||||||||||||||||||||||
| 43 | my @paths; | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 24 | ▶ | for (my $i = 0, my $next_token, my $token_type, my $token_data; my $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 100 | $next_token = $tokens->[$i+1]; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 100 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 100 | $token_data = $token->{data}; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 100 | ▶ | if ($token_type == PACKAGE) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 24 | ▶ | if ($next_token->{type} == CLASS) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | push @paths, { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | path => "$next_token->{data}", | ||||||||||||||||||||||||||||||||||||||||||
| 52 | line => $token->{line}, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 8 | }; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 8 | next; | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 16 | my $path = ''; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 16 | ▶ | for ($i++; my $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 68 | my $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 68 | ▶ | if ($token_type == NAMESPACE) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 34 | $path .= $token->{data}; | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | elsif ($token_type == NAMESPACE_RESOLVER) { | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 18 | $path .= '/'; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 67 | push @paths, { | ||||||||||||||||||||||||||||||||||||||||||
| 68 | path => $path, | ||||||||||||||||||||||||||||||||||||||||||
| 69 | line => $token->{line}, | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 16 | }; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 16 | last; | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 24 | for my $p (@paths) { | |||||||||||||||||||||||||||||||||||||||||
| 78 | 23 | my $is_directive_declared_after = 0; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 23 | my $should_be_no_error = 0; | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 23 | my $path = $p->{path}; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 23 | my $package_declared_line = $p->{line}; | |||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 23 | ▶ | if ($directive_declared_row && $package_declared_line < $directive_declared_row) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$directive_declared_row and $package_declared_line < $directive_declared_row
MC/DC100%2/2
$directive_declared_row and $package_declared_line < $directive_declared_row
$directive_declared_row
$package_declared_line < $directive_declared_row
Truth table100%3/3
A and B
A= $directive_declared_rowB= $package_declared_line < $directive_declared_row
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | $is_directive_declared_after = 1; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 23 | my $last_path = @{[split(/\//, $path)]}[-1]; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 23 | (my $module_name = $path) =~ s!/!-!; | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 23 | ▶ | if ($path eq 'main' && !$is_directive_declared_after) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$path eq "main" and not $is_directive_declared_after
MC/DC50%1/2
$path eq "main" and not $is_directive_declared_after
$path eq "main"
not $is_directive_declared_after
Truth table66%2/3
A and not(B)
A= $path eq "main"B= not $is_directive_declared_after
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 2 | last; | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | elsif (defined $file) { | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 21 | ▶ | if ($file !~ m!/!) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 8 | ▶ | my $last_path = @{[split(/\//, $path)]}[-1] || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
@{[split(m[/], $path, 0)];}[-1] || ''
MC/DC0%0/1
@{[split(m[/], $path, 0)];}[-1] || ''
@{[split(m[/], $path, 0)];}[-1]
Truth table50%1/2
A
A= @{[split(m[/], $path, 0)];}[-1]
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 8 | ▶ | if ($file =~ /$last_path\.p[ml]/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 5 | $should_be_no_error = 1; | |||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | elsif ($file =~ /$path\.p[ml]/) { | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 6 | $should_be_no_error = 1; | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | elsif ($file =~ m!$module_name(?:-\d[\d\.]*?\d)?/$last_path!) { | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 2 | $should_be_no_error = 1; | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | elsif ($file =~ m![A-Z]\w*-\d[\d\.]*\d/$last_path!) { | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | $should_be_no_error = 1; | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 21 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not $should_be_no_error or $should_be_no_error and $is_directive_declared_after
$should_be_no_error and $is_directive_declared_after
MC/DC66%2/3
not $should_be_no_error or $should_be_no_error and $is_directive_declared_after
not $should_be_no_error
$should_be_no_error
$is_directive_declared_after
Truth table75%3/4
not(A) or B and C
A= not $should_be_no_errorB= $should_be_no_errorC= $is_directive_declared_after
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | !$should_be_no_error || | ||||||||||||||||||||||||||||||||||||||||||
| 114 | ($should_be_no_error && $is_directive_declared_after) | ||||||||||||||||||||||||||||||||||||||||||
| 115 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 8 | push @violations, { | |||||||||||||||||||||||||||||||||||||||||
| 117 | filename => $realfile, | ||||||||||||||||||||||||||||||||||||||||||
| 118 | line => $package_declared_line, | ||||||||||||||||||||||||||||||||||||||||||
| 119 | description => DESC, | ||||||||||||||||||||||||||||||||||||||||||
| 120 | explanation => EXPL, | ||||||||||||||||||||||||||||||||||||||||||
| 121 | policy => __PACKAGE__, | ||||||||||||||||||||||||||||||||||||||||||
| 122 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 24 | return \@violations; | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||