« Perl/Lint/Policy/Modules/RequireEndWithOne.pm
↑ Summary
Perl/Lint/Policy/ControlStructures/ProhibitCascadingIfElse.pm »
| 1 | package Perl::Lint::Policy::Modules::RequireExplicitPackage; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 List::Util qw/any/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Perl::Lint::Constants::Type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use parent "Perl::Lint::Policy"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | DESC => 'Code not contained in explicit package', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | EXPL => 'Violates encapsulation', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | ▶ | sub evaluate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
evaluate: not called CC=13 SCAR=52.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | my ($class, $file, $tokens, $src, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | my @violations; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | my $exempt_scripts = $args->{require_explicit_package}->{exempt_scripts}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | my $allow_import_of = $args->{require_explicit_package}->{allow_import_of}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | my $token = $tokens->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | if (($exempt_scripts || !$token || $token->{type} == PACKAGE) && !$allow_import_of) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$exempt_scripts || !$token || $token->{"type"} == 128 and not $allow_import_of
$exempt_scripts or not $token or $token->{"type"} == 128
$exempt_scripts or not $token
MC/DC0%0/4
$exempt_scripts || !$token || $token->{"type"} == 128 and not $allow_import_of
$exempt_scripts
not $token
$token->{"type"} == 128
not $allow_import_of
Truth table0%0/7
A or not(B) or C and not(D)
A= $exempt_scriptsB= not $tokenC= $token->{"type"} == 128D= not $allow_import_of
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | return []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | for (my $i = 0; my $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | my $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | my $token_data = $token->{data}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | if ($token_type == USE_DECL) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | my $used_name = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | for ($i++; my $token = $tokens->[$i]; $i++) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | my $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | my $token_data = $token->{data}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$token_type != 127 and $token_type != 126 and $token_type != 94
$token_type != 127 and $token_type != 126
MC/DC0%0/3
$token_type != 127 and $token_type != 126 and $token_type != 94
$token_type != 127
$token_type != 126
$token_type != 94
Truth table0%0/4
A and B and C
A= $token_type != 127B= $token_type != 126C= $token_type != 94
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | $token_type != NAMESPACE && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | $token_type != NAMESPACE_RESOLVER && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | $token_type != USED_NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | $used_name .= $token_data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if (!any {$_ eq $used_name} @$allow_import_of) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | push @violations, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | filename => $file, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | line => $token->{line}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | description => DESC, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | explanation => EXPL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | policy => __PACKAGE__, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | elsif ($token_type == PACKAGE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | push @violations, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | filename => $file, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | line => $token->{line}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | description => DESC, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | explanation => EXPL, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | policy => __PACKAGE__, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | return \@violations; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||