Perl/Lint/Policy/ValuesAndExpressions/RequireInterpolationOfMetachars.pm

filter: Statementstmt 62.6% 42 / 67 Branchbran 43.3% 13 / 30 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 88.8% 8 / 9 Podpod 0.0% 0 / 1 totaltotal 50.0% 63 / 126 CC 21 SCAR 45.4
CC
21
Cov
50%
evaluate
128.7
__ANON__
2.0
BEGIN
1.0
CRAP 93.5
« Perl/Lint/Policy/ValuesAndExpressions/ProhibitInterpolationOfLiterals.pm ↑ Summary Perl/Lint/Policy/BuiltinFunctions/RequireSimpleSortBlock.pm »
1 package Perl::Lint::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Perl::Lint::Constants::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use List::Util qw/any/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Email::Address;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 DESC => 'String *may* require interpolation',
11 EXPL => [51],
12 3 };
13  
14 2 ▶sub evaluate {
Subroutine evaluate: called CC=21 SCAR=48.6
Pod undocumented
15 2 my ($class, $file, $tokens, $src, $args) = @_;
16  
17 2 my @rcs_keywords = ();
18 2 ▶ if (my $this_policies_arg = $args->{require_interpolation_of_matchers}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $this_policies_arg = $args->{"require_interpolation_of_matchers"}) 0 2 2
19 0 ▶ @rcs_keywords = split /\s+/, $this_policies_arg->{rcs_keywords} || '';
Condition0%0/2
$this_policies_arg->{'rcs_keywords'} || ''
l!l
00
MC/DC0%0/1
$this_policies_arg->{'rcs_keywords'} || ''
$this_policies_arg->{'rcs_keywords'}
Truth table0%0/2
A
A= $this_policies_arg->{'rcs_keywords'}
Aresult
11
00
20 }
21  
22 2 my $is_used_vers = 0;
23  
24 2 my @violations;
25 2 ▶ for (my $i = 0, my $token_type, my $token_data; my $token = $tokens->[$i]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $tokens->[$i]) 51 2 53
26 51 $token_type = $token->{type};
27 51 $token_data = $token->{data};
28  
29 51 ▶ if ($token_type == USED_NAME) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 94) 8 43 51
30 8 ▶ if ($token_data eq 'vars') {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data eq "vars") 0 8 8
31 0 $is_used_vers = 1;
32 }
33 8 next;
34 }
35  
36 43 ▶ if ($token_type == REG_QUOTE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 145) 0 43 43
37 0 $i++; # skip reg delimiter
38 0 $token = $tokens->[++$i];
39  
40 0 $token_data = $token->{data}; # It is REG_EXP, e.g. q{THIS ONE}
41 0 $token_type = RAW_STRING; # XXX
42 } # straight through!
43 43 ▶ if ($token_type == RAW_STRING) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 173) 1 42 43
44 1 ▶ if ($is_used_vers) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_used_vers) 0 1 1
45 0 next;
46 }
47  
48 1 ▶ if (my @captures = $token_data =~ /
Branch: 1 branch
BranchTrueFalseTotal
if (my(@captures) = $token_data =~ / (\\*) (?: [\$\@]([^\s{]\S*) | \\[tnrfbae01234567xcNluLUEQ] )/gx) 0 1 1
49 (\\*)
50 (?:
51 [\$\@]([^\s{]\S*) |
52 \\[tnrfbae01234567xcNluLUEQ]
53 )/gx
54 ) {
55 0 my $length_of_captures = scalar @captures;
56 0 my $is_violated = 0;
57 0 ▶ for (my $i = 0; $i < $length_of_captures; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $length_of_captures) 0 0 0
58 0 ▶ if ($i % 2 == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i % 2 == 0) { } 0 0 0
59 0 my $backslash = $captures[$i];
60 0 ▶ if (length($backslash) % 2 == 0) { # check escaped or not
Branch: 1 branch
BranchTrueFalseTotal
if (length($backslash) % 2 == 0) 0 0 0
61 0 $is_violated = 1;
62 }
63 } else {
64 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (index($token_data, "\@") != -1 and not $token_data =~ / \W \@ /msx and not $token_data =~ / \A \@ \w+ \b /msx and $token_data =~ /$Email::Address::addr_spec/) 0 0 0
Condition0%0/9
index($token_data, "\@") != -1 and not $token_data =~ / \W \@ /msx and not $token_data =~ / \A \@ \w+ \b /msx and $token_data =~ /$Email::Address::addr_spec/
!ll&&!rl&&r
000
index($token_data, "\@") != -1 and not $token_data =~ / \W \@ /msx and not $token_data =~ / \A \@ \w+ \b /msx
!ll&&!rl&&r
000
index($token_data, "\@") != -1 and not $token_data =~ / \W \@ /msx
!ll&&!rl&&r
000
MC/DC0%0/4
index($token_data, "\@") != -1 and not $token_data =~ / \W \@ /msx and not $token_data =~ / \A \@ \w+ \b /msx and $token_data =~ /$Email::Address::addr_spec/
index($token_data, "\@") != -1 not $token_data =~ / \W \@ /msx not $token_data =~ / \A \@ \w+ \b /msx $token_data =~ /$Email::Address::addr_spec/
Truth table0%0/5
A and not(B) and not(C) and D
A= index($token_data, "\@") != -1B= not $token_data =~ / \W \@ /msxC= not $token_data =~ / \A \@ \w+ \b /msxD= $token_data =~ /$Email::Address::addr_spec/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
65 # ports from Perl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars
66 index ($token_data, q<@>) >= 0 &&
67 $token_data !~ m< \W \@ >xms &&
68 $token_data !~ m< \A \@ \w+ \b >xms &&
69 $token_data =~ $Email::Address::addr_spec
70 ) {
71 0 next;
72 }
73  
74 0 ▶ my ($var_name) = ($captures[$i] || '') =~ /\A(\w+)/;
Condition0%0/2
$captures[$i] || ''
l!l
00
MC/DC0%0/1
$captures[$i] || ''
$captures[$i]
Truth table0%0/2
A
A= $captures[$i]
Aresult
11
00
75  
76 0 ▶ if (any {$_ eq $var_name} @rcs_keywords) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $_ eq $var_name; } , @rcs_keywords)) 0 0 0
77 0 $is_violated = 0;
78 0 next;
79 }
80  
81 0 ▶ if ($is_violated) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_violated) 0 0 0
82 push @violations, {
83 filename => $file,
84 line => $token->{line},
85 0 description => DESC,
86 explanation => EXPL,
87 policy => __PACKAGE__,
88 };
89 0 $is_violated = 0;
90 0 last;
91 }
92 }
93 }
94 }
95  
96 1 next;
97 }
98  
99 42 ▶ if ($token_type == SEMI_COLON) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_type == 106) 11 31 42
100 11 $is_used_vers = 0;
101 11 next;
102 }
103 }
104  
105 2 return \@violations;
106 }
107  
108 3 1;
109  
« Perl/Lint/Policy/ValuesAndExpressions/ProhibitInterpolationOfLiterals.pm ↑ Summary Perl/Lint/Policy/BuiltinFunctions/RequireSimpleSortBlock.pm »