« 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | @rcs_keywords = split /\s+/, $this_policies_arg->{rcs_keywords} || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$this_policies_arg->{'rcs_keywords'} || ''
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'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 51 | $token_type = $token->{type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 51 | $token_data = $token->{data}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 51 | ▶ | if ($token_type == USED_NAME) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 8 | ▶ | if ($token_data eq 'vars') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | $is_used_vers = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 8 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 43 | ▶ | if ($token_type == REG_QUOTE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | ▶ | if ($is_used_vers) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | if (my @captures = $token_data =~ / | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if ($i % 2 == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my $backslash = $captures[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if (length($backslash) % 2 == 0) { # check escaped or not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $is_violated = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
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/
index($token_data, "\@") != -1 and not $token_data =~ / \W \@ /msx and not $token_data =~ / \A \@ \w+ \b /msx
index($token_data, "\@") != -1 and not $token_data =~ / \W \@ /msx
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/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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] || ''
MC/DC0%0/1
$captures[$i] || ''
$captures[$i]
Truth table0%0/2
A
A= $captures[$i]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if (any {$_ eq $var_name} @rcs_keywords) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $is_violated = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | if ($is_violated) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 11 | $is_used_vers = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 11 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 2 | return \@violations; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||