Perl/Lint/Policy/InputOutput/ProhibitBacktickOperators.pm

filter: Statementstmt 32.2% 19 / 59 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 85.7% 6 / 7 Podpod 0.0% 0 / 1 totaltotal 21.0% 25 / 119 CC 20 SCAR 57.8
CC
20
Cov
19%
evaluate
420.0
BEGIN
1.0
BEGIN
1.0
CRAP 323.3
« Perl/Lint/Policy/Variables/ProhibitMatchVars.pm ↑ Summary Perl/Lint/Policy/TestingAndDebugging/ProhibitNoWarnings.pm »
1 package Perl::Lint::Policy::InputOutput::ProhibitBacktickOperators;
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 => 'Backtick operator used',
10 EXPL => 'Use IPC::Open3 instead',
11 VOID_DESC => 'Backtick operator used in void context',
12 VOID_EXPL => 'Assign result to a variable or use system() instead',
13 2 };
14  
15 0 ▶sub evaluate {
Subroutine evaluate: not called CC=20 SCAR=60.4
Pod undocumented
16 0 my ($class, $file, $tokens, $src, $args) = @_;
17  
18 0 my $only_in_void_context = $args->{prohibit_backtick_operators}->{only_in_void_context};
19  
20 0 my @violations;
21 my $is_in_assign_context;
22 0 my $is_in_call_context;
23 0 my $is_in_ctrl_context;
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_kind = $token->{kind};
27  
28 0 ▶ if ($token_type == BUILTIN_FUNC || $token_type == KEY) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 70 or $token_type == 122) 0 0 0
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
29 0 $is_in_call_context = 1;
30 0 next;
31 }
32  
33 0 ▶ if ($token_kind == KIND_STMT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_kind == 17) 0 0 0
34 0 $is_in_ctrl_context = 1;
35 0 next;
36 }
37  
38 0 ▶ if ($only_in_void_context && ($is_in_call_context || $is_in_ctrl_context)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($only_in_void_context and $is_in_call_context || $is_in_ctrl_context) 0 0 0
Condition0%0/6
$only_in_void_context and $is_in_call_context || $is_in_ctrl_context
!ll&&!rl&&r
000
$is_in_call_context or $is_in_ctrl_context
l!l&&r!l&&!r
000
MC/DC0%0/3
$only_in_void_context and $is_in_call_context || $is_in_ctrl_context
$only_in_void_context $is_in_call_context $is_in_ctrl_context
Truth table0%0/4
A and B or C
A= $only_in_void_contextB= $is_in_call_contextC= $is_in_ctrl_context
ABCresult
0XX0
1000
11X1
1011
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 ▶ for ($i++; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 0 0 0
42 0 my $token_type = $token->{type};
43 0 ▶ if ($token_type == LEFT_PAREN) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 107) { } 0 0 0
elsif ($token_type == 108) { } 0 0 0
44 0 $left_paren_num++;
45 }
46 elsif ($token_type == RIGHT_PAREN) {
47 0 ▶ last if --$left_paren_num <= 0
Branch: 1 branch
BranchTrueFalseTotal
if --$left_paren_num <= 0 0 0 0
48 }
49 }
50 }
51 0 $is_in_call_context = 0;
52 0 $is_in_ctrl_context = 0;
53 0 next;
54 }
55  
56 0 ▶ if ($token_type == ASSIGN) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 65) 0 0 0
57 0 $is_in_assign_context = 1;
58 0 next;
59 }
60  
61 0 ▶ if ($token_type == SEMI_COLON) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 106) 0 0 0
62 0 $is_in_assign_context = 0;
63 0 next;
64 }
65  
66 0 ▶ if ($token_type == EXEC_STRING || $token_type == REG_EXEC) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 174 or $token_type == 148) 0 0 0
Condition0%0/3
$token_type == 174 or $token_type == 148
l!l&&r!l&&!r
000
MC/DC0%0/2
$token_type == 174 or $token_type == 148
$token_type == 174 $token_type == 148
Truth table0%0/3
A or B
A= $token_type == 174B= $token_type == 148
ABresult
1X1
011
000
67 0 ▶ next if ($only_in_void_context && $is_in_assign_context);
Branch: 1 branch
BranchTrueFalseTotal
if $only_in_void_context and $is_in_assign_context 0 0 0
Condition0%0/3
$only_in_void_context and $is_in_assign_context
!ll&&!rl&&r
000
MC/DC0%0/2
$only_in_void_context and $is_in_assign_context
$only_in_void_context $is_in_assign_context
Truth table0%0/3
A and B
A= $only_in_void_contextB= $is_in_assign_context
ABresult
0X0
100
111
68  
69 0 my $desc = VOID_DESC;
70 0 my $expl = VOID_EXPL;
71 0 ▶ if ($is_in_assign_context) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_in_assign_context) 0 0 0
72 0 $desc = DESC;
73 0 $expl = EXPL;
74 }
75  
76 push @violations, {
77 filename => $file,
78 line => $token->{line},
79 0 description => $desc,
80 explanation => $expl,
81 policy => __PACKAGE__,
82 };
83 }
84 }
85  
86 0 return \@violations;
87 }
88  
89 2 1;
90  
« Perl/Lint/Policy/Variables/ProhibitMatchVars.pm ↑ Summary Perl/Lint/Policy/TestingAndDebugging/ProhibitNoWarnings.pm »