Perl/Lint/Policy/ErrorHandling/RequireCarping.pm

filter: Statementstmt 27.1% 22 / 81 Branchbran 0.0% 0 / 62 Conditioncond 0.0% 0 / 80 MC/DCmcdc 0.0% 0 / 35 Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 1 totaltotal 10.8% 29 / 267 CC 59 SCAR 79.7
CC
59
Cov
10%
evaluate
3246.0
BEGIN
1.0
BEGIN
1.0
CRAP 2901.8
« Perl/Lint/Policy/InputOutput/RequireCheckedOpen.pm ↑ Summary Perl/Lint/Policy/Subroutines/RequireFinalReturn.pm »
1 package Perl::Lint::Policy::ErrorHandling::RequireCarping;
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 => q{Don't complain about die or warn if the message ends in a newline},
9 EXPL => [283],
10 2 };
11  
12 0 ▶sub evaluate {
Subroutine evaluate: not called CC=59 SCAR=80.9
Pod undocumented
13 0 my ($class, $file, $tokens, $src, $args) = @_;
14  
15 0 my $options = $args->{require_carping};
16 0 my $allow_messages_ending_with_newlines = 1;
17 0 ▶ if (defined $options->{allow_messages_ending_with_newlines}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options->{"allow_messages_ending_with_newlines"}) 0 0 0
18 $allow_messages_ending_with_newlines =
19 0 $options->{allow_messages_ending_with_newlines};
20 }
21 my $allow_in_main_unless_in_subroutine =
22 0 ▶ $options->{allow_in_main_unless_in_subroutine } || 0;
Condition0%0/2
$options->{'allow_in_main_unless_in_subroutine'} || 0
l!l
00
MC/DC0%0/1
$options->{'allow_in_main_unless_in_subroutine'} || 0
$options->{'allow_in_main_unless_in_subroutine'}
Truth table0%0/2
A
A= $options->{'allow_in_main_unless_in_subroutine'}
Aresult
11
00
23  
24 0 my $is_in_main = 1;
25 0 my $is_in_sub = 0;
26  
27 0 my $left_brace_num = 0;
28  
29 0 my @violations;
30 0 my $token_num = scalar @$tokens;
31  
32 0 ▶ for (my $i = 0; $i < $token_num; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $token_num) 0 0 0
33 0 my $token = $tokens->[$i];
34 0 my $token_type = $token->{type};
35 0 my $token_data = $token->{data};
36  
37 0 ▶ if (
Branch: 5 branches
BranchTrueFalseTotal
if ($token_type eq 70 and $token_data eq 'die' || $token_data eq 'warn') { } 0 0 0
elsif ($token_type == 128) { } 0 0 0
elsif ($token_type == 63) { } 0 0 0
elsif ($token_type == 109) { } 0 0 0
elsif ($token_type == 110) { } 0 0 0
Condition0%0/6
$token_type eq 70 and $token_data eq "die" || $token_data eq "warn"
!ll&&!rl&&r
000
$token_data eq "die" or $token_data eq "warn"
l!l&&r!l&&!r
000
MC/DC0%0/3
$token_type eq 70 and $token_data eq "die" || $token_data eq "warn"
$token_type eq 70 $token_data eq "die" $token_data eq "warn"
Truth table0%0/4
A and B or C
A= $token_type eq 70B= $token_data eq "die"C= $token_data eq "warn"
ABCresult
0XX0
1000
11X1
1011
38 $token_type eq BUILTIN_FUNC &&
39 ($token_data eq 'die' || $token_data eq 'warn')
40 ) {
41 0 my %last_msg;
42 0 ▶ for ($i++; $i <= $token_num; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $token_num) 0 0 0
43 0 $token = $tokens->[$i];
44 0 $token_type = $token->{type};
45 0 $token_data = $token->{data};
46  
47 2 ▶ no warnings qw/uninitialized/;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 0 ▶ if ($token_type == STRING) {
Branch: 10 branches
BranchTrueFalseTotal
if ($token_type == 172) { } 0 0 0
elsif ($token_type == 146) { } 0 0 0
elsif ($token_type == 173) { } 0 0 0
elsif ($token_type == 145) { } 0 0 0
elsif ($token_type == 176 or $token_type == 177) { } 0 0 0
elsif ($i + 1 >= $token_num or $token_type == 106 or $token_type == 96 or $token_type == 99 or $token_type == 132 or $token_type == 133 or $token_type == 134 or $token_type == 100 or $token_type == 182) { } 0 0 0
elsif ($token_type == 64) { } 0 0 0
elsif ($token_type == 70 or $token_type == 122) { } 0 0 0
elsif ($token_type != 151 and $token_type != 104 and $token_type != 108 and $token_type != 181 and $token_type != 180) { } 0 0 0
elsif ($token_type == 128) { } 0 0 0
49 0 %last_msg = (type => 'not_raw', data => $token_data);
50 }
51 elsif ($token_type == REG_DOUBLE_QUOTE) {
52 0 %last_msg = (type => 'not_raw', data => $tokens->[$i+=2]->{data});
53 }
54 elsif ($token_type == RAW_STRING) {
55 0 %last_msg = (type => 'raw', data => $token_data);
56 }
57 elsif ($token_type == REG_QUOTE) {
58 0 %last_msg = (type => 'raw', data => $tokens->[$i+=2]->{data});
59 }
60 ▶ elsif ($token_type == HERE_DOCUMENT_TAG || $token_type == HERE_DOCUMENT_RAW_TAG) {
Condition0%0/3
$token_type == 176 or $token_type == 177
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 176 or $token_type == 177
$token_type == 176 $token_type == 177
Truth table0%0/3
A or B
A= $token_type == 176B= $token_type == 177
ABresult
1X1
011
000
61 0 %last_msg = (type => 'heredoc', data => $token_data);
62 }
63 ▶ elsif (
Condition0%0/24
$i + 1 >= $token_num or $token_type == 106 or $token_type == 96 or $token_type == 99 or $token_type == 132 or $token_type == 133 or $token_type == 134 or $token_type == 100 or $token_type == 182
l!l&&r!l&&!r
000
$i + 1 >= $token_num or $token_type == 106 or $token_type == 96 or $token_type == 99 or $token_type == 132 or $token_type == 133 or $token_type == 134 or $token_type == 100
l!l&&r!l&&!r
000
$i + 1 >= $token_num or $token_type == 106 or $token_type == 96 or $token_type == 99 or $token_type == 132 or $token_type == 133 or $token_type == 134
l!l&&r!l&&!r
000
$i + 1 >= $token_num or $token_type == 106 or $token_type == 96 or $token_type == 99 or $token_type == 132 or $token_type == 133
l!l&&r!l&&!r
000
$i + 1 >= $token_num or $token_type == 106 or $token_type == 96 or $token_type == 99 or $token_type == 132
l!l&&r!l&&!r
000
$i + 1 >= $token_num or $token_type == 106 or $token_type == 96 or $token_type == 99
l!l&&r!l&&!r
000
$i + 1 >= $token_num or $token_type == 106 or $token_type == 96
l!l&&r!l&&!r
000
$i + 1 >= $token_num or $token_type == 106
l!l&&r!l&&!r
000
MC/DC0%0/9
$i + 1 >= $token_num or $token_type == 106 or $token_type == 96 or $token_type == 99 or $token_type == 132 or $token_type == 133 or $token_type == 134 or $token_type == 100 or $token_type == 182
$i + 1 >= $token_num $token_type == 106 $token_type == 96 $token_type == 99 $token_type == 132 $token_type == 133 $token_type == 134 $token_type == 100 $token_type == 182
Truth table0%0/10
A or B or C or D or E or F or G or H or I
A= $i + 1 >= $token_numB= $token_type == 106C= $token_type == 96D= $token_type == 99E= $token_type == 132F= $token_type == 133G= $token_type == 134H= $token_type == 100I= $token_type == 182
ABCDEFGHIresult
1XXXXXXXX1
01XXXXXXX1
001XXXXXX1
0001XXXXX1
00001XXXX1
000001XXX1
0000001XX1
00000001X1
0000000011
0000000000
64 $i + 1 >= $token_num ||
65 $token_type == SEMI_COLON ||
66 $token_type == IF_STATEMENT ||
67 $token_type == UNLESS_STATEMENT ||
68 $token_type == WHILE_STATEMENT ||
69 $token_type == FOR_STATEMENT ||
70 $token_type == FOREACH_STATEMENT ||
71 $token_type == UNTIL_STATEMENT ||
72 $token_type == HERE_DOCUMENT_END
73 ) {
74 0 my $last_msg_type = $last_msg{type};
75 0 my $last_msg_data = $last_msg{data};
76  
77 0 ▶ if(
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $last_msg_type && defined $last_msg_data or $last_msg_type eq "raw" and substr($last_msg_data, -1) ne "\n" || !$allow_messages_ending_with_newlines or $last_msg_type eq "not_raw" and not $last_msg_data =~ /(?:\\n|\n)\Z/ && $allow_messages_ending_with_newlines) 0 0 0
Condition0%0/21
not defined $last_msg_type && defined $last_msg_data or $last_msg_type eq "raw" and substr($last_msg_data, -1) ne "\n" || !$allow_messages_ending_with_newlines or $last_msg_type eq "not_raw" and not $last_msg_data =~ /(?:\\n|\n)\Z/ && $allow_messages_ending_with_newlines
l!l&&r!l&&!r
000
not defined $last_msg_type && defined $last_msg_data or $last_msg_type eq "raw" and substr($last_msg_data, -1) ne "\n" || !$allow_messages_ending_with_newlines
l!l&&r!l&&!r
000
defined $last_msg_type && defined $last_msg_data
!ll&&!rl&&r
000
$last_msg_type eq "raw" and substr($last_msg_data, -1) ne "\n" || !$allow_messages_ending_with_newlines
!ll&&!rl&&r
000
substr($last_msg_data, -1) ne "\n" or not $allow_messages_ending_with_newlines
l!l&&r!l&&!r
000
$last_msg_type eq "not_raw" and not $last_msg_data =~ /(?:\\n|\n)\Z/ && $allow_messages_ending_with_newlines
!ll&&!rl&&r
000
$last_msg_data =~ /(?:\\n|\n)\Z/ && $allow_messages_ending_with_newlines
!ll&&!rl&&r
000
MC/DC0%0/8
not defined $last_msg_type && defined $last_msg_data or $last_msg_type eq "raw" and substr($last_msg_data, -1) ne "\n" || !$allow_messages_ending_with_newlines or $last_msg_type eq "not_raw" and not $last_msg_data =~ /(?:\\n|\n)\Z/ && $allow_messages_ending_with_newlines
defined $last_msg_type defined $last_msg_data $last_msg_type eq "raw" substr($last_msg_data, -1) ne "\n" not $allow_messages_ending_with_newlines $last_msg_type eq "not_raw" $last_msg_data =~ /(?:\\n|\n)\Z/ $allow_messages_ending_with_newlines
Truth table0%0/12
not(A && B) or C and D or not(E) or F and not(G && H)
A= defined $last_msg_typeB= defined $last_msg_dataC= $last_msg_type eq "raw"D= substr($last_msg_data, -1) ne "\n"E= not $allow_messages_ending_with_newlinesF= $last_msg_type eq "not_raw"G= $last_msg_data =~ /(?:\\n|\n)\Z/H= $allow_messages_ending_with_newlines
ABCDEFGHresult
0XXXXXXX1
10XXXXXX1
1111XXXX1
11101XXX1
110XX10X1
110XX1101
1110010X1
111001101
110XX0XX0
110XX1110
111000XX0
111001110
78 !(defined $last_msg_type && defined $last_msg_data) ||
79 ($last_msg_type eq 'raw' && (substr($last_msg_data, -1) ne "\n" || !$allow_messages_ending_with_newlines)) ||
80 ($last_msg_type eq 'not_raw' && ($last_msg_data !~ /(?:\\n|\n)\Z/ || !$allow_messages_ending_with_newlines))
81 ) {
82 0 ▶ if ($is_in_sub || !($is_in_main && $allow_in_main_unless_in_subroutine)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_in_sub or not $is_in_main && $allow_in_main_unless_in_subroutine) 0 0 0
Condition0%0/6
$is_in_sub or not $is_in_main && $allow_in_main_unless_in_subroutine
l!l&&r!l&&!r
000
$is_in_main && $allow_in_main_unless_in_subroutine
!ll&&!rl&&r
000
MC/DC0%0/3
$is_in_sub or not $is_in_main && $allow_in_main_unless_in_subroutine
$is_in_sub $is_in_main $allow_in_main_unless_in_subroutine
Truth table0%0/4
A or not(B && C)
A= $is_in_subB= $is_in_mainC= $allow_in_main_unless_in_subroutine
ABCresult
1XX1
00X1
0101
0110
83 push @violations, {
84 filename => $file,
85 line => $token->{line} // $tokens->[-1]->{line},
86 0 ▶ description => DESC,
Condition0%0/3
$token->{"line"} // $tokens->[-1]{"line"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$token->{"line"} // $tokens->[-1]{"line"}
$token->{"line"} $tokens->[-1]{"line"}
Truth table0%0/3
A // B
A= $token->{"line"}B= $tokens->[-1]{"line"}
ABresult
1X1
011
000
87 explanation => EXPL,
88 policy => __PACKAGE__,
89 };
90 }
91 }
92 0 last;
93 }
94 elsif ($token_type == METHOD) {
95 0 $i++; # Skip a left parenthesis
96 0 my $left_paren_num = 1;
97 0 ▶ for ($i++; $i < $token_num; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $token_num) 0 0 0
98 0 my $token_type = $tokens->[$i]->{type};
99  
100 0 ▶ if ($token_type == RIGHT_PAREN) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 108) { } 0 0 0
elsif ($token_type == 107) { } 0 0 0
101 0 $left_paren_num--;
102 }
103 elsif ($token_type == LEFT_PAREN) {
104 0 $left_paren_num++;
105 }
106  
107 0 ▶ if ($left_paren_num <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($left_paren_num <= 0) 0 0 0
108 0 last;
109 }
110 }
111 }
112 ▶ elsif (
Condition0%0/3
$token_type == 70 or $token_type == 122
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 70 or $token_type == 122
$token_type == 70 $token_type == 122
Truth table0%0/3
A or B
A= $token_type == 70B= $token_type == 122
ABresult
1X1
011
000
113 $token_type == BUILTIN_FUNC ||
114 $token_type == KEY
115 ) {
116 0 my $left_paren_num = 0;
117 0 ▶ for ($i++; $i < $token_num; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $token_num) 0 0 0
118 0 my $token_type = $tokens->[$i]->{type};
119  
120 0 ▶ if ($token_type == RIGHT_PAREN) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 108) { } 0 0 0
elsif ($token_type == 107) { } 0 0 0
121 0 $left_paren_num--;
122 }
123 elsif ($token_type == LEFT_PAREN) {
124 0 $left_paren_num++;
125 }
126  
127 0 ▶ if ($left_paren_num <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($left_paren_num <= 0) 0 0 0
128 0 last;
129 }
130 }
131 }
132 ▶ elsif (
Condition0%0/12
$token_type != 151 and $token_type != 104 and $token_type != 108 and $token_type != 181 and $token_type != 180
!ll&&!rl&&r
000
$token_type != 151 and $token_type != 104 and $token_type != 108 and $token_type != 181
!ll&&!rl&&r
000
$token_type != 151 and $token_type != 104 and $token_type != 108
!ll&&!rl&&r
000
$token_type != 151 and $token_type != 104
!ll&&!rl&&r
000
MC/DC0%0/5
$token_type != 151 and $token_type != 104 and $token_type != 108 and $token_type != 181 and $token_type != 180
$token_type != 151 $token_type != 104 $token_type != 108 $token_type != 181 $token_type != 180
Truth table0%0/6
A and B and C and D and E
A= $token_type != 151B= $token_type != 104C= $token_type != 108D= $token_type != 181E= $token_type != 180
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
133 $token_type != REG_DELIM &&
134 $token_type != COMMA &&
135 $token_type != RIGHT_PAREN &&
136 $token_type != HERE_DOCUMENT &&
137 $token_type != RAW_HERE_DOCUMENT
138 ) {
139 0 %last_msg = ();
140 }
141 elsif ($token_type == PACKAGE) {
142 0 ▶ $is_in_main = $tokens->[++$i]->{data} eq 'main' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$$tokens[++$i]{'data'} eq 'main' ? : 0 0 0
143 }
144  
145 2 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
146 }
147 }
148 elsif ($token_type == PACKAGE) {
149 0 ▶ $is_in_main = $tokens->[++$i]->{data} eq 'main' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$$tokens[++$i]{'data'} eq 'main' ? : 0 0 0
150 }
151 elsif ($token_type == FUNCTION_DECL) {
152 0 $is_in_sub = 1;
153 }
154 elsif ($token_type == LEFT_BRACE) {
155 0 $left_brace_num++;
156 }
157 elsif ($token_type == RIGHT_BRACE) {
158 0 $left_brace_num--;
159 0 ▶ if ($left_brace_num <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($left_brace_num <= 0) 0 0 0
160 0 $is_in_sub = 0;
161 }
162 }
163 }
164  
165 0 return \@violations;
166 }
167  
168 2 1;
169  
« Perl/Lint/Policy/InputOutput/RequireCheckedOpen.pm ↑ Summary Perl/Lint/Policy/Subroutines/RequireFinalReturn.pm »