Perl/Lint/Policy/InputOutput/ProhibitTwoArgOpen.pm

filter: Statementstmt 29.6% 19 / 64 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 48 MC/DCmcdc 0.0% 0 / 22 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 1 totaltotal 14.0% 25 / 178 CC 35 SCAR 69.8
CC
35
Cov
13%
evaluate
1260.0
BEGIN
1.0
BEGIN
1.0
CRAP 1075.8
« Perl/Lint/Policy/Subroutines/ProtectPrivateSubs.pm ↑ Summary Perl/Lint/Policy/Variables/ProhibitPunctuationVars.pm »
1 package Perl::Lint::Policy::InputOutput::ProhibitTwoArgOpen;
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 Perl::Lint::Constants::Kind;
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 => 'Two-argument "open" used',
10 EXPL => [207],
11 2 };
12  
13 0 ▶sub evaluate {
Subroutine evaluate: not called CC=35 SCAR=71.4
Pod undocumented
14 0 my ($class, $file, $tokens, $src, $args) = @_;
15  
16 0 my @violations;
17 0 ▶ for (my $i = 0; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
18 0 my $token_type = $token->{type};
19 0 my $token_data = $token->{data};
20  
21 0 ▶ if ($token_type == USE_DECL) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 93) { } 0 0 0
elsif ($token_type == 70 and $token_data eq 'open') { } 0 0 0
22 # Skip when `use (<=5.005)`
23 0 $i++;
24 0 my $token = $tokens->[$i];
25 0 my $token_type = $token->{type};
26 0 my $token_data = $token->{data};
27 0 ▶ if ($token_type == DOUBLE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 171) 0 0 0
28 0 $token_data =~ s/_//g;
29 0 ▶ if ($token_data <= 5.005) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data <= "5.005") 0 0 0
30 0 return [];
31 }
32 }
33 }
34 ▶ elsif ($token_type == BUILTIN_FUNC && $token_data eq 'open') {
Condition0%0/3
$token_type == 70 and $token_data eq "open"
!ll&&!rl&&r
000
MC/DC0%0/2
$token_type == 70 and $token_data eq "open"
$token_type == 70 $token_data eq "open"
Truth table0%0/3
A and B
A= $token_type == 70B= $token_data eq "open"
ABresult
0X0
100
111
35 0 $i++;
36 0 my $token = $tokens->[$i];
37 0 my $token_type = $token->{type};
38  
39 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
40 0 my $left_paren_num = 1;
41 0 my @args;
42 0 ▶ for ($i++; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
43 0 my $token_type = $token->{type};
44 0 my $token_kind = $token->{kind};
45  
46 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 3 branches
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
elsif ($token_type == 108) { } 0 0 0
elsif ($token_type != 104 and $token_type != 146 and $token_type != 145 and $token_type != 151 and $token_kind != 3) { } 0 0 0
47 0 $left_paren_num++;
48 }
49 elsif ($token_type == RIGHT_PAREN) {
50 0 ▶ last if --$left_paren_num <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if --$left_paren_num <= 0 0 0 0
51 }
52 ▶ elsif (
Condition0%0/12
$token_type != 104 and $token_type != 146 and $token_type != 145 and $token_type != 151 and $token_kind != 3
!ll&&!rl&&r
000
$token_type != 104 and $token_type != 146 and $token_type != 145 and $token_type != 151
!ll&&!rl&&r
000
$token_type != 104 and $token_type != 146 and $token_type != 145
!ll&&!rl&&r
000
$token_type != 104 and $token_type != 146
!ll&&!rl&&r
000
MC/DC0%0/5
$token_type != 104 and $token_type != 146 and $token_type != 145 and $token_type != 151 and $token_kind != 3
$token_type != 104 $token_type != 146 $token_type != 145 $token_type != 151 $token_kind != 3
Truth table0%0/6
A and B and C and D and E
A= $token_type != 104B= $token_type != 146C= $token_type != 145D= $token_type != 151E= $token_kind != 3
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
53 $token_type != COMMA &&
54 $token_type != REG_DOUBLE_QUOTE &&
55 $token_type != REG_QUOTE &&
56 $token_type != REG_DELIM &&
57 $token_kind != KIND_DECL
58 ) {
59 0 push @args, $token->{data};
60 }
61 }
62 0 ▶ if (scalar @args < 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @args < 3) 0 0 0
63 0 my $second = $args[1];
64 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($second and $second eq "-|" || $second eq "|-" || $second =~ /STD(?:OUT|ERR|IN)\Z/) 0 0 0
Condition0%0/9
$second and $second eq "-|" || $second eq "|-" || $second =~ /STD(?:OUT|ERR|IN)\Z/
!ll&&!rl&&r
000
$second eq "-|" or $second eq "|-" or $second =~ /STD(?:OUT|ERR|IN)\Z/
l!l&&r!l&&!r
000
$second eq "-|" or $second eq "|-"
l!l&&r!l&&!r
000
MC/DC0%0/4
$second and $second eq "-|" || $second eq "|-" || $second =~ /STD(?:OUT|ERR|IN)\Z/
$second $second eq "-|" $second eq "|-" $second =~ /STD(?:OUT|ERR|IN)\Z/
Truth table0%0/5
A and B or C or D
A= $secondB= $second eq "-|"C= $second eq "|-"D= $second =~ /STD(?:OUT|ERR|IN)\Z/
ABCDresult
0XXX0
10000
11XX1
101X1
10011
65 $second &&
66 (
67 $second eq '-|' || $second eq '|-' ||
68 $second =~ /STD(?:OUT|ERR|IN)\Z/
69 )
70 ) {
71 0 next;
72 }
73  
74 push @violations, {
75 filename => $file,
76 line => $token->{line},
77 0 description => DESC,
78 explanation => EXPL,
79 policy => __PACKAGE__,
80 };
81 }
82 }
83 else {
84 0 my @args;
85 0 ▶ for (; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
86 0 my $token_type = $token->{type};
87 0 my $token_kind = $token->{kind};
88 0 ▶ if ($token_kind == KIND_STMT_END || $token_kind == KIND_OP) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_kind == 21 or $token_kind == 1) { } 0 0 0
elsif ($token_type != 104 and $token_type != 146 and $token_type != 145 and $token_type != 151 and $token_kind != 3) { } 0 0 0
Condition0%0/3
$token_kind == 21 or $token_kind == 1
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_kind == 21 or $token_kind == 1
$token_kind == 21 $token_kind == 1
Truth table0%0/3
A or B
A= $token_kind == 21B= $token_kind == 1
ABresult
1X1
011
000
89 0 last;
90 }
91 ▶ elsif (
Condition0%0/12
$token_type != 104 and $token_type != 146 and $token_type != 145 and $token_type != 151 and $token_kind != 3
!ll&&!rl&&r
000
$token_type != 104 and $token_type != 146 and $token_type != 145 and $token_type != 151
!ll&&!rl&&r
000
$token_type != 104 and $token_type != 146 and $token_type != 145
!ll&&!rl&&r
000
$token_type != 104 and $token_type != 146
!ll&&!rl&&r
000
MC/DC0%0/5
$token_type != 104 and $token_type != 146 and $token_type != 145 and $token_type != 151 and $token_kind != 3
$token_type != 104 $token_type != 146 $token_type != 145 $token_type != 151 $token_kind != 3
Truth table0%0/6
A and B and C and D and E
A= $token_type != 104B= $token_type != 146C= $token_type != 145D= $token_type != 151E= $token_kind != 3
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
92 $token_type != COMMA &&
93 $token_type != REG_DOUBLE_QUOTE &&
94 $token_type != REG_QUOTE &&
95 $token_type != REG_DELIM &&
96 $token_kind != KIND_DECL
97 ) {
98 0 push @args, $token->{data};
99 }
100 }
101 0 ▶ if (scalar @args < 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @args < 3) 0 0 0
102 0 my $second = $args[1];
103 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($second and $second eq "-|" || $second eq "|-" || $second =~ /STD(?:OUT|ERR|IN)\Z/) 0 0 0
Condition0%0/9
$second and $second eq "-|" || $second eq "|-" || $second =~ /STD(?:OUT|ERR|IN)\Z/
!ll&&!rl&&r
000
$second eq "-|" or $second eq "|-" or $second =~ /STD(?:OUT|ERR|IN)\Z/
l!l&&r!l&&!r
000
$second eq "-|" or $second eq "|-"
l!l&&r!l&&!r
000
MC/DC0%0/4
$second and $second eq "-|" || $second eq "|-" || $second =~ /STD(?:OUT|ERR|IN)\Z/
$second $second eq "-|" $second eq "|-" $second =~ /STD(?:OUT|ERR|IN)\Z/
Truth table0%0/5
A and B or C or D
A= $secondB= $second eq "-|"C= $second eq "|-"D= $second =~ /STD(?:OUT|ERR|IN)\Z/
ABCDresult
0XXX0
10000
11XX1
101X1
10011
104 $second &&
105 (
106 $second eq '-|' || $second eq '|-' ||
107 $second =~ /STD(?:OUT|ERR|IN)\Z/
108 )
109 ) {
110 0 next;
111 }
112 push @violations, {
113 filename => $file,
114 line => $token->{line},
115 0 description => DESC,
116 explanation => EXPL,
117 policy => __PACKAGE__,
118 };
119 }
120 }
121 }
122 }
123  
124 0 return \@violations;
125 }
126  
127 2 1;
128  
« Perl/Lint/Policy/Subroutines/ProtectPrivateSubs.pm ↑ Summary Perl/Lint/Policy/Variables/ProhibitPunctuationVars.pm »