Perl/Lint/Policy/Subroutines/ProtectPrivateSubs.pm

filter: Statementstmt 29.0% 16 / 55 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 55 MC/DCmcdc 0.0% 0 / 27 Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 12.3% 21 / 170 CC 35 SCAR 70.1
CC
35
Cov
12%
evaluate
1260.0
BEGIN
1.0
BEGIN
1.0
CRAP 1102.6
« Perl/Lint/Policy/ValuesAndExpressions/RequireConstantVersion.pm ↑ Summary Perl/Lint/Policy/InputOutput/ProhibitTwoArgOpen.pm »
1 package Perl::Lint::Policy::Subroutines::ProtectPrivateSubs;
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 => 'Private subroutine/method used',
9 EXPL => 'Use published APIs',
10 2 };
11  
12 0 ▶sub evaluate {
Subroutine evaluate: not called CC=35 SCAR=71.4
Pod undocumented
13 0 my ($class, $file, $tokens, $src, $args) = @_;
14  
15 0 my @allows = ();
16 0 ▶ for my $allow (split(/ /, $args->{protect_private_subs}->{allow} || '')) {
Condition0%0/2
$args->{'protect_private_subs'}{'allow'} || ''
l!l
00
MC/DC0%0/1
$args->{'protect_private_subs'}{'allow'} || ''
$args->{'protect_private_subs'}{'allow'}
Truth table0%0/2
A
A= $args->{'protect_private_subs'}{'allow'}
Aresult
11
00
17 0 my @name_spaces = split /::/, $allow;
18 0 my $method_name = pop @name_spaces;
19 0 push @allows, +{
20 package_name => join('::', @name_spaces),
21 method_name => $method_name,
22 };
23 }
24 0 ▶ my $private_name_regex = $args->{protect_private_subs}->{private_name_regex} || '';
Condition0%0/2
$args->{'protect_private_subs'}{'private_name_regex'} || ''
l!l
00
MC/DC0%0/1
$args->{'protect_private_subs'}{'private_name_regex'} || ''
$args->{'protect_private_subs'}{'private_name_regex'}
Truth table0%0/2
A
A= $args->{'protect_private_subs'}{'private_name_regex'}
Aresult
11
00
25  
26 0 my @violations;
27 0 my $module_name = '';
28 0 ▶ TOP: for (my $i = 0; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
29 0 my $token_type = $token->{type};
30 0 my $token_data = $token->{data};
31  
32 0 ▶ if ($token_type == POINTER || $token_type == NAMESPACE_RESOLVER) {
Branch: 6 branches
BranchTrueFalseTotal
if ($token_type == 125 or $token_type == 126) { } 0 0 0
elsif ($token_type == 93 or $token_type == 71 or $token_type == 128) { } 0 0 0
elsif ($token_type == 73 and $token_data eq '__PACKAGE__' or $token_type == 70 and $token_data eq 'shift' or $token_type == 127 and $token_data eq 'POSIX') { } 0 0 0
elsif ($token_type == 127) { } 0 0 0
elsif ($token_type == 166 || $token_type == 194 || $token_type == 191 and $token_data eq '$pkg' || $token_data eq '$self') { } 0 0 0
elsif ($token_type == 106) { } 0 0 0
Condition0%0/3
$token_type == 125 or $token_type == 126
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 125 or $token_type == 126
$token_type == 125 $token_type == 126
Truth table0%0/3
A or B
A= $token_type == 125B= $token_type == 126
ABresult
1X1
011
000
33 0 my $delimiter = $token_data;
34  
35 0 $token = $tokens->[++$i];
36 0 $token_data = $token->{data};
37 0 my $next_token = $tokens->[$i+1];
38 0 my $next_token_type = $next_token->{type};
39 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (substr($token_data, 0, 1) eq '_' and $next_token_type != 125 and $next_token_type != 126) { } 0 0 0
Condition0%0/6
substr($token_data, 0, 1) eq "_" and $next_token_type != 125 and $next_token_type != 126
!ll&&!rl&&r
000
substr($token_data, 0, 1) eq "_" and $next_token_type != 125
!ll&&!rl&&r
000
MC/DC0%0/3
substr($token_data, 0, 1) eq "_" and $next_token_type != 125 and $next_token_type != 126
substr($token_data, 0, 1) eq "_" $next_token_type != 125 $next_token_type != 126
Truth table0%0/4
A and B and C
A= substr($token_data, 0, 1) eq "_"B= $next_token_type != 125C= $next_token_type != 126
ABCresult
0XX0
10X0
1100
1111
40 substr($token_data, 0, 1) eq '_' &&
41 $next_token_type != POINTER &&
42 $next_token_type != NAMESPACE_RESOLVER
43 ) {
44 0 for my $allow (@allows) {
45 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($allow->{"package_name"} eq $module_name and $allow->{"method_name"} eq $token_data) 0 0 0
Condition0%0/3
$allow->{"package_name"} eq $module_name and $allow->{"method_name"} eq $token_data
!ll&&!rl&&r
000
MC/DC0%0/2
$allow->{"package_name"} eq $module_name and $allow->{"method_name"} eq $token_data
$allow->{"package_name"} eq $module_name $allow->{"method_name"} eq $token_data
Truth table0%0/3
A and B
A= $allow->{"package_name"} eq $module_nameB= $allow->{"method_name"} eq $token_data
ABresult
0X0
100
111
46 $allow->{package_name} eq $module_name &&
47 $allow->{method_name} eq $token_data
48 ) {
49 0 next TOP;
50 }
51 }
52  
53 0 ▶ if ($private_name_regex && $token_data =~ /$private_name_regex/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($private_name_regex and $token_data =~ /$private_name_regex/) 0 0 0
Condition0%0/3
$private_name_regex and $token_data =~ /$private_name_regex/
!ll&&!rl&&r
000
MC/DC0%0/2
$private_name_regex and $token_data =~ /$private_name_regex/
$private_name_regex $token_data =~ /$private_name_regex/
Truth table0%0/3
A and B
A= $private_name_regexB= $token_data =~ /$private_name_regex/
ABresult
0X0
100
111
54 0 next;
55 }
56  
57 push @violations, {
58 filename => $file,
59 line => $token->{line},
60 0 description => DESC,
61 explanation => EXPL,
62 policy => __PACKAGE__,
63 };
64 0 $module_name = '';
65 }
66 else {
67 0 $module_name .= $delimiter . $token_data;
68 }
69 }
70 ▶ elsif (
Condition0%0/6
$token_type == 93 or $token_type == 71 or $token_type == 128
l!l&&r!l&&!r
000
$token_type == 93 or $token_type == 71
l!l&&r!l&&!r
000
MC/DC0%0/3
$token_type == 93 or $token_type == 71 or $token_type == 128
$token_type == 93 $token_type == 71 $token_type == 128
Truth table0%0/4
A or B or C
A= $token_type == 93B= $token_type == 71C= $token_type == 128
ABCresult
1XX1
01X1
0011
0000
71 $token_type == USE_DECL ||
72 $token_type == REQUIRE_DECL ||
73 $token_type == PACKAGE
74 ) {
75 0 ▶ for ($i++; $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $tokens->[$i]) 0 0 0
76 0 $token_type = $token->{type};
77 0 ▶ if ($token_type == SEMI_COLON) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 106) 0 0 0
78 0 last;
79 }
80 }
81 }
82 ▶ elsif (
Condition0%0/15
$token_type == 73 and $token_data eq "__PACKAGE__" or $token_type == 70 and $token_data eq "shift" or $token_type == 127 and $token_data eq "POSIX"
l!l&&r!l&&!r
000
$token_type == 73 and $token_data eq "__PACKAGE__" or $token_type == 70 and $token_data eq "shift"
l!l&&r!l&&!r
000
$token_type == 73 and $token_data eq "__PACKAGE__"
!ll&&!rl&&r
000
$token_type == 70 and $token_data eq "shift"
!ll&&!rl&&r
000
$token_type == 127 and $token_data eq "POSIX"
!ll&&!rl&&r
000
MC/DC0%0/6
$token_type == 73 and $token_data eq "__PACKAGE__" or $token_type == 70 and $token_data eq "shift" or $token_type == 127 and $token_data eq "POSIX"
$token_type == 73 $token_data eq "__PACKAGE__" $token_type == 70 $token_data eq "shift" $token_type == 127 $token_data eq "POSIX"
Truth table0%0/15
A and B or C and D or E and F
A= $token_type == 73B= $token_data eq "__PACKAGE__"C= $token_type == 70D= $token_data eq "shift"E= $token_type == 127F= $token_data eq "POSIX"
ABCDEFresult
11XXXX1
0X11XX1
1011XX1
0X0X111
0X10111
100X111
1010111
0X0X0X0
0X0X100
0X100X0
0X10100
100X0X0
100X100
10100X0
1010100
83 ($token_type == SPECIFIC_KEYWORD && $token_data eq '__PACKAGE__') ||
84 ($token_type == BUILTIN_FUNC && $token_data eq 'shift') ||
85 ($token_type == NAMESPACE && $token_data eq 'POSIX')
86 ) {
87 0 $i++; # skip target func
88 }
89 elsif ($token_type == NAMESPACE) {
90 0 $module_name .= $token_data;
91 }
92 ▶ elsif (
Condition0%0/12
$token_type == 166 || $token_type == 194 || $token_type == 191 and $token_data eq "\$pkg" || $token_data eq "\$self"
!ll&&!rl&&r
000
$token_type == 166 or $token_type == 194 or $token_type == 191
l!l&&r!l&&!r
000
$token_type == 166 or $token_type == 194
l!l&&r!l&&!r
000
$token_data eq "\$pkg" or $token_data eq "\$self"
l!l&&r!l&&!r
000
MC/DC0%0/5
$token_type == 166 || $token_type == 194 || $token_type == 191 and $token_data eq "\$pkg" || $token_data eq "\$self"
$token_type == 166 $token_type == 194 $token_type == 191 $token_data eq "\$pkg" $token_data eq "\$self"
Truth table0%0/10
A or B or C and D or E
A= $token_type == 166B= $token_type == 194C= $token_type == 191D= $token_data eq "\$pkg"E= $token_data eq "\$self"
ABCDEresult
000XX0
1XX000
01X000
001000
1XX1X1
1XX011
01X1X1
01X011
0011X1
001011
93 (
94 $token_type == VAR ||
95 $token_type == GLOBAL_VAR ||
96 $token_type == LOCAL_VAR
97 ) && ($token_data eq '$pkg' || $token_data eq '$self')
98 ) {
99 0 $i++;
100 0 my $next_token = $tokens->[$i+1];
101 0 ▶ if ($next_token->{type} == NAMESPACE && $next_token->{data} eq 'SUPER') {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_token->{"type"} == 127 and $next_token->{"data"} eq "SUPER") 0 0 0
Condition0%0/3
$next_token->{"type"} == 127 and $next_token->{"data"} eq "SUPER"
!ll&&!rl&&r
000
MC/DC0%0/2
$next_token->{"type"} == 127 and $next_token->{"data"} eq "SUPER"
$next_token->{"type"} == 127 $next_token->{"data"} eq "SUPER"
Truth table0%0/3
A and B
A= $next_token->{"type"} == 127B= $next_token->{"data"} eq "SUPER"
ABresult
0X0
100
111
102 0 $i += 2;
103 }
104 }
105 elsif ($token_type == SEMI_COLON) {
106 0 $module_name = '';
107 }
108 }
109  
110 0 return \@violations;
111 }
112  
113 2 1;
114  
« Perl/Lint/Policy/ValuesAndExpressions/RequireConstantVersion.pm ↑ Summary Perl/Lint/Policy/InputOutput/ProhibitTwoArgOpen.pm »