« lib/Perl/Critic/Policy/Documentation/RequirePodSections.pm
↑ Summary
lib/Perl/Critic/Policy/ControlStructures/ProhibitPostfixControls.pm »
| 1 | package Perl::Critic::Policy::ValuesAndExpressions::RequireInterpolationOfMetachars; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 40 | ▶ | use 5.010001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 40 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 40 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 40 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 40 | ▶ | use List::SomeUtils qw(any); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 40 | ▶ | use Perl::Critic::Utils qw< :booleans :characters :severities >; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 40 | ▶ | use parent 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 40 | our $VERSION = '1.156'; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 40 | Readonly::Scalar my $DESC => q<String *may* require interpolation>; | |||||||||||||||||||||||||||
| 20 | 40 | Readonly::Scalar my $EXPL => [ 51 ]; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 91 | ▶ | sub supported_parameters { | ||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | return ( | ||||||||||||||||||||||||||||
| 26 | { | ||||||||||||||||||||||||||||
| 27 | 91 | name => 'rcs_keywords', | |||||||||||||||||||||||||||
| 28 | description => 'RCS keywords to ignore in potential interpolation.', | ||||||||||||||||||||||||||||
| 29 | default_string => $EMPTY, | ||||||||||||||||||||||||||||
| 30 | behavior => 'string list', | ||||||||||||||||||||||||||||
| 31 | }, | ||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 74 | ▶ | sub default_severity { return $SEVERITY_LOWEST } | ||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | 83 | ▶ | sub default_themes { return qw(core pbp cosmetic) } | ||||||||||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 31 | ▶ | sub applies_to { | ||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 31 | return qw< PPI::Token::Quote::Single PPI::Token::Quote::Literal >; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 47 | ▶ | sub initialize_if_enabled { | ||||||||||||||||||||||||||
|
Subroutine
initialize_if_enabled: called CC=2 SCAR=7.8
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 47 | my ($self, undef) = @_; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 47 | my $rcs_keywords = $self->{_rcs_keywords}; | |||||||||||||||||||||||||||
| 48 | 47 | my @rcs_keywords = keys %{$rcs_keywords}; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 47 | ▶ | if (@rcs_keywords) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | my $rcs_regexes = [ map { qr/ \$ $_ [^\n\$]* \$ /xms } @rcs_keywords ]; | |||||||||||||||||||||||||||
| 52 | 0 | $self->{_rcs_regexes} = $rcs_regexes; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 47 | return $TRUE; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 71 | ▶ | sub violates { | ||||||||||||||||||||||||||
|
Subroutine
violates: called CC=6 SCAR=32.2
Pod
documented
| |||||||||||||||||||||||||||||
| 59 | 71 | my ( $self, $elem, undef ) = @_; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | # The string() method strips off the quotes | ||||||||||||||||||||||||||||
| 62 | 71 | my $string = $elem->string(); | |||||||||||||||||||||||||||
| 63 | 71 | ▶ | return if not _needs_interpolation($string); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | return if _looks_like_email_address($string); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | return if _looks_like_use_vars($elem); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | my $rcs_regexes = $self->{_rcs_regexes}; | |||||||||||||||||||||||||||
| 68 | 0 | ▶ | return if $rcs_regexes && any { $string =~ m/$_/xms } @{$rcs_regexes}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
Condition0%0/3
$rcs_regexes and &any(sub {
$string =~ /$_/msx;
}
, @{$rcs_regexes;})
MC/DC0%0/2
$rcs_regexes and &any(sub {
$string =~ /$_/msx;
}
, @{$rcs_regexes;})
$rcs_regexes
&any(sub {
$string =~ /$_/msx;
}
, @{$rcs_regexes;})
Truth table0%0/3
A and B
A= $rcs_regexesB= &any(sub {
$string =~ /$_/msx;
}
, @{$rcs_regexes;})
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | return $self->violation( $DESC, $EXPL, $elem ); | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 71 | ▶ | sub _needs_interpolation { | ||||||||||||||||||||||||||
|
Subroutine
_needs_interpolation: called CC=2 SCAR=8.1
| |||||||||||||||||||||||||||||
| 76 | 71 | my ($string) = @_; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | return | ||||||||||||||||||||||||||||
| 79 | # Contains a $ or @ not followed by "{}". | ||||||||||||||||||||||||||||
| 80 | 71 | ▶ | $string =~ m< [\$\@] (?! [{] [}] ) \S+ >xms | ||||||||||||||||||||||||||
|
Condition33%1/3
$string =~ / [\$\@] (?! [{] [}] ) \S+ /msx || $string =~ /
(?: \A | [^\\] )
(?: \\{2} )*
\\ [tnrfbae01234567xcNluLUEQ]
/msx
MC/DC0%0/2
$string =~ / [\$\@] (?! [{] [}] ) \S+ /msx || $string =~ /
(?: \A | [^\\] )
(?: \\{2} )*
\\ [tnrfbae01234567xcNluLUEQ]
/msx
$string =~ / [\$\@] (?! [{] [}] ) \S+ /msx
$string =~ /
(?: \A | [^\\] )
(?: \\{2} )*
\\ [tnrfbae01234567xcNluLUEQ]
/msx
Truth table33%1/3
A || B
A= $string =~ / [\$\@] (?! [{] [}] ) \S+ /msxB= $string =~ /
(?: \A | [^\\] )
(?: \\{2} )*
\\ [tnrfbae01234567xcNluLUEQ]
/msx
| |||||||||||||||||||||||||||||
| 81 | # Contains metachars | ||||||||||||||||||||||||||||
| 82 | # Note that \1 ... are not documented (that I can find), but are | ||||||||||||||||||||||||||||
| 83 | # treated the same way as \0 by S_scan_const in toke.c, at least | ||||||||||||||||||||||||||||
| 84 | # for regular double-quotish strings. Not, obviously, where | ||||||||||||||||||||||||||||
| 85 | # regexes are involved. | ||||||||||||||||||||||||||||
| 86 | || $string =~ m< | ||||||||||||||||||||||||||||
| 87 | (?: \A | [^\\] ) | ||||||||||||||||||||||||||||
| 88 | (?: \\{2} )* | ||||||||||||||||||||||||||||
| 89 | \\ [tnrfbae01234567xcNluLUEQ] | ||||||||||||||||||||||||||||
| 90 | >xms; | ||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | # Stolen from Email::Address, which is deprecated. Since we are not modifying | ||||||||||||||||||||||||||||
| 96 | # the original code at all, we are less stringent in being Critic-compliant. | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | ## no critic ( RegularExpressions::RequireDotMatchAnything ) | ||||||||||||||||||||||||||||
| 99 | ## no critic ( RegularExpressions::RequireLineBoundaryMatching ) | ||||||||||||||||||||||||||||
| 100 | ## no critic ( RegularExpressions::ProhibitEscapedMetacharacters ) | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 40 | my $CTL = q{\x00-\x1F\x7F}; ## no critic ( ValuesAndExpressions::RequireInterpolationOfMetachars ) | |||||||||||||||||||||||||||
| 103 | 40 | my $special = q{()<>\\[\\]:;@\\\\,."}; ## no critic ( ValuesAndExpressions::RequireInterpolationOfMetachars ) | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 40 | my $text = qr/[^\x0A\x0D]/x; | |||||||||||||||||||||||||||
| 106 | 40 | my $quoted_pair = qr/\\$text/x; | |||||||||||||||||||||||||||
| 107 | 40 | my $ctext = qr/(?>[^()\\]+)/x; | |||||||||||||||||||||||||||
| 108 | 40 | my $ccontent = qr/$ctext|$quoted_pair/x; | |||||||||||||||||||||||||||
| 109 | 40 | my $comment = qr/\s*\((?:\s*$ccontent)*\s*\)\s*/x; | |||||||||||||||||||||||||||
| 110 | 40 | my $cfws = qr/$comment|\s+/x; | |||||||||||||||||||||||||||
| 111 | 40 | my $atext = qq/[^$CTL$special\\s]/; | |||||||||||||||||||||||||||
| 112 | 40 | my $dot_atom_text = qr/$atext+(?:\.$atext+)*/x; | |||||||||||||||||||||||||||
| 113 | 40 | my $dot_atom = qr/$cfws*$dot_atom_text$cfws*/x; | |||||||||||||||||||||||||||
| 114 | 40 | my $qtext = qr/[^\\"]/x; | |||||||||||||||||||||||||||
| 115 | 40 | my $qcontent = qr/$qtext|$quoted_pair/x; | |||||||||||||||||||||||||||
| 116 | 40 | my $quoted_string = qr/$cfws*"$qcontent*"$cfws*/x; | |||||||||||||||||||||||||||
| 117 | 40 | my $local_part = qr/$dot_atom|$quoted_string/x; | |||||||||||||||||||||||||||
| 118 | 40 | my $dtext = qr/[^\[\]\\]/x; | |||||||||||||||||||||||||||
| 119 | 40 | my $dcontent = qr/$dtext|$quoted_pair/x; | |||||||||||||||||||||||||||
| 120 | 40 | my $domain_literal = qr/$cfws*\[(?:\s*$dcontent)*\s*\]$cfws*/x; | |||||||||||||||||||||||||||
| 121 | 40 | my $domain = qr/$dot_atom|$domain_literal/x; | |||||||||||||||||||||||||||
| 122 | 40 | my $addr_spec = qr/$local_part\@$domain/x; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | sub _looks_like_email_address { | ||||||||||||||||||||||||||
|
Subroutine
_looks_like_email_address: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 125 | 0 | my ($string) = @_; | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 0 | ▶ | return if index ($string, q<@>) < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 0 | ▶ | return if $string =~ m< \W \@ >xms; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | 0 | ▶ | return if $string =~ m< \A \@ \w+ \b >xms; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | return $string =~ $addr_spec; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | ▶ | sub _looks_like_use_vars { | ||||||||||||||||||||||||||
|
Subroutine
_looks_like_use_vars: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 137 | 0 | my ($elem) = @_; | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 0 | my $statement = $elem; | |||||||||||||||||||||||||||
| 140 | 0 | ▶ | while ( not $statement->isa('PPI::Statement::Include') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | $statement = $statement->parent() or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 0 | ▶ | return if $statement->type() ne q<use>; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | 0 | return $statement->module() eq q<vars>; | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 40 | 1; | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | __END__ | ||||||||||||||||||||||||||||