Perl/Lint/Policy/ValuesAndExpressions/ProhibitInterpolationOfLiterals.pm

filter: Statementstmt 51.8% 28 / 54 Branchbran 19.2% 5 / 26 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 1 totaltotal 43.4% 40 / 92 CC 16 SCAR 45.6
CC
16
Cov
40%
evaluate
136.4
__ANON__
2.0
BEGIN
1.0
CRAP 95.3
« Perl/Lint/Policy/CodeLayout/RequireTrailingCommas.pm ↑ Summary Perl/Lint/Policy/ValuesAndExpressions/RequireInterpolationOfMetachars.pm »
1 package Perl::Lint::Policy::ValuesAndExpressions::ProhibitInterpolationOfLiterals;
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 List::Util qw/any/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Perl::Lint::Constants::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use parent "Perl::Lint::Policy";
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 DESC => 'Useless interpolation of literal string',
10 EXPL => [51],
11 3 };
12  
13 # TODO integrate duplicated functions
14  
15 2 ▶sub evaluate {
Subroutine evaluate: called CC=16 SCAR=49.2
Pod undocumented
16 2 my ($class, $file, $tokens, $src, $args) = @_;
17  
18 2 my @allow_double_quote_literals;
19 my $allow_if_string_contains_single_quote;
20 2 ▶ if (my $this_policies_arg = $args->{prohibit_interpolation_of_literals}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $this_policies_arg = $args->{"prohibit_interpolation_of_literals"}) 0 2 2
21 0 $allow_if_string_contains_single_quote = $this_policies_arg->{allow_if_string_contains_single_quote};
22  
23 # e.g. {allow => 'qq( qq{ qq[ qq/'}}
24 0 my $allow_double_quote_literals = $this_policies_arg->{allow};
25 0 ▶ for my $allowed_literal (split /\s+/, $allow_double_quote_literals || '') {
Condition0%0/2
$allow_double_quote_literals || ''
l!l
00
MC/DC0%0/1
$allow_double_quote_literals || ''
$allow_double_quote_literals
Truth table0%0/2
A
A= $allow_double_quote_literals
Aresult
11
00
26 0 $allowed_literal =~ s/\Aqq//;
27 0 push @allow_double_quote_literals, substr $allowed_literal, 0, 1;
28 }
29 }
30  
31  
32 2 my @violations;
33 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
34 51 $token_type = $token->{type};
35 51 $token_data = $token->{data};
36  
37 51 ▶ if ($token_type == STRING) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token_type == 172) { } 0 51 51
elsif ($token_type == 146) { } 0 51 51
38 0 ▶ if ($allow_if_string_contains_single_quote) {
Branch: 1 branch
BranchTrueFalseTotal
if ($allow_if_string_contains_single_quote) 0 0 0
39 0 ▶ if ($token_data =~ /'/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data =~ /'/) 0 0 0
40 0 next;
41 }
42 }
43  
44 # XXX NP? :(
45 0 ▶ if ($token_data =~ /(\\*)(?:[\$\@]|\\\w)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data =~ /(\\*)(?:[\$\@]|\\\w)/) 0 0 0
46 0 ▶ if (length($1) % 2 == 0) { # check escaped or not
Branch: 1 branch
BranchTrueFalseTotal
if (length($1) % 2 == 0) 0 0 0
47 0 next;
48 }
49 }
50  
51 push @violations, {
52 filename => $file,
53 line => $token->{line},
54 0 description => DESC,
55 explanation => EXPL,
56 policy => __PACKAGE__,
57 };
58 }
59 elsif ($token_type == REG_DOUBLE_QUOTE) {
60 0 $token = $tokens->[++$i];
61 0 $token_data = $token->{data};
62  
63 0 ▶ if (any {$_ eq $token_data} @allow_double_quote_literals) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $_ eq $token_data; } , @allow_double_quote_literals)) 0 0 0
64 0 next;
65 }
66  
67 0 $token = $tokens->[++$i];
68 0 $token_data = $token->{data};
69 0 ▶ if ($allow_if_string_contains_single_quote) {
Branch: 1 branch
BranchTrueFalseTotal
if ($allow_if_string_contains_single_quote) 0 0 0
70 0 ▶ if ($token_data =~ /'/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data =~ /'/) 0 0 0
71 0 next;
72 }
73 }
74  
75 # XXX NP? :(
76 0 ▶ if ($token_data =~ /(\\*)(?:[\$\@]\S+|\\\w)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token_data =~ /(\\*)(?:[\$\@]\S+|\\\w)/) 0 0 0
77 0 ▶ if (length($1) % 2 == 0) { # check escaped or not
Branch: 1 branch
BranchTrueFalseTotal
if (length($1) % 2 == 0) 0 0 0
78 0 next;
79 }
80 }
81  
82 push @violations, {
83 filename => $file,
84 line => $token->{line},
85 0 description => DESC,
86 explanation => EXPL,
87 policy => __PACKAGE__,
88 };
89 }
90 }
91  
92 2 return \@violations;
93 }
94  
95 3 1;
96  
« Perl/Lint/Policy/CodeLayout/RequireTrailingCommas.pm ↑ Summary Perl/Lint/Policy/ValuesAndExpressions/RequireInterpolationOfMetachars.pm »