Perl/Lint/Policy/Modules/RequireExplicitPackage.pm

filter: Statementstmt 42.2% 19 / 45 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 75.0% 6 / 8 Podpod 0.0% 0 / 1 totaltotal 27.7% 25 / 90 CC 13 SCAR 47.8
CC
13
Cov
26%
evaluate
182.0
__ANON__
2.0
BEGIN
1.0
CRAP 118.7
« 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
BranchTrueFalseTotal
if ($exempt_scripts || !$token || $token->{'type'} == 128 and not $allow_import_of) { } 0 0 0
Condition0%0/9
$exempt_scripts || !$token || $token->{"type"} == 128 and not $allow_import_of
!ll&&!rl&&r
000
$exempt_scripts or not $token or $token->{"type"} == 128
l!l&&r!l&&!r
000
$exempt_scripts or not $token
l!l&&r!l&&!r
000
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
ABCDresult
000X0
1XX00
01X00
00100
1XX11
01X11
00111
21 0 return [];
22 }
23 else {
24 0 ▶ for (my $i = 0; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
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
BranchTrueFalseTotal
if ($token_type == 93) { } 0 0 0
elsif ($token_type == 128) { } 0 0 0
29 0 my $used_name = '';
30 0 ▶ for ($i++; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
31 0 my $token_type = $token->{type};
32 0 my $token_data = $token->{data};
33 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type != 127 and $token_type != 126 and $token_type != 94) { } 0 0 0
Condition0%0/6
$token_type != 127 and $token_type != 126 and $token_type != 94
!ll&&!rl&&r
000
$token_type != 127 and $token_type != 126
!ll&&!rl&&r
000
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
ABCresult
0XX0
10X0
1100
1111
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
BranchTrueFalseTotal
unless (&any(sub { $_ eq $used_name; } , @$allow_import_of)) 0 0 0
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  
« Perl/Lint/Policy/Modules/RequireEndWithOne.pm ↑ Summary Perl/Lint/Policy/ControlStructures/ProhibitCascadingIfElse.pm »