« lib/Perl/Critic/Policy/ValuesAndExpressions/RequireConstantVersion.pm
↑ Summary
lib/Perl/Critic/Policy/RegularExpressions/ProhibitUnusedCapture.pm »
| 1 | package Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 Perl::Critic::Utils qw{ :severities hashify }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 40 | ▶ | use parent 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 40 | our $VERSION = '1.156'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 40 | Readonly::Scalar my $DESC => q{Subroutine called with "&" sigil}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 40 | Readonly::Scalar my $EXPL => [ 175 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 40 | Readonly::Hash my %EXEMPTIONS => | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | hashify( qw< defined exists goto sort > ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 40 | Readonly::Hash my %IS_COMMA => | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | hashify( q{,}, q{=>} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 90 | ▶ | sub supported_parameters { return () } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 74 | ▶ | sub default_severity { return $SEVERITY_LOW } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 85 | ▶ | sub default_themes { return qw(core pbp maintenance) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 31 | ▶ | sub applies_to { return 'PPI::Token::Symbol' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 173 | ▶ | sub violates { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
violates: called CC=19 SCAR=54.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 173 | my ( $self, $elem, undef ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 173 | my $previous = $elem->sprevious_sibling(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 173 | ▶ | if ( $previous ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | #Sigil is allowed if taking a reference, e.g. "\&my_sub" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 131 | ▶ | return if $previous->isa('PPI::Token::Cast') && $previous eq q{\\}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$previous->isa("PPI::Token::Cast") and $previous eq "\\"
MC/DC0%0/2
$previous->isa("PPI::Token::Cast") and $previous eq "\\"
$previous->isa("PPI::Token::Cast")
$previous eq "\\"
Truth table33%1/3
A and B
A= $previous->isa("PPI::Token::Cast")B= $previous eq "\\"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 173 | ▶ | return if ( $elem !~ m{\A [&] }xms ); # ok | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # look up past parens to get say the "defined" in "defined(&foo)" or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # "defined((&foo))" etc | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | if (not $previous or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not $previous or $previous->isa("PPI::Token::Operator") and $IS_COMMA{$previous->content}
$previous->isa("PPI::Token::Operator") and $IS_COMMA{$previous->content}
MC/DC0%0/3
not $previous or $previous->isa("PPI::Token::Operator") and $IS_COMMA{$previous->content}
not $previous
$previous->isa("PPI::Token::Operator")
$IS_COMMA{$previous->content}
Truth table0%0/4
not(A) or B and C
A= not $previousB= $previous->isa("PPI::Token::Operator")C= $IS_COMMA{$previous->content}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | $previous->isa( 'PPI::Token::Operator' ) and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | $IS_COMMA{ $previous->content() } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my $up = $elem; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | PARENT: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | while ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$up = $up->parent and $up->isa("PPI::Statement::Expression") || $up->isa("PPI::Structure::List") || $up->isa("PPI::Statement")
$up->isa("PPI::Statement::Expression") or $up->isa("PPI::Structure::List") or $up->isa("PPI::Statement")
$up->isa("PPI::Statement::Expression") or $up->isa("PPI::Structure::List")
MC/DC0%0/4
$up = $up->parent and $up->isa("PPI::Statement::Expression") || $up->isa("PPI::Structure::List") || $up->isa("PPI::Statement")
$up = $up->parent
$up->isa("PPI::Statement::Expression")
$up->isa("PPI::Structure::List")
$up->isa("PPI::Statement")
Truth table0%0/5
A and B or C or D
A= $up = $up->parentB= $up->isa("PPI::Statement::Expression")C= $up->isa("PPI::Structure::List")D= $up->isa("PPI::Statement")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | ($up = $up->parent) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | and ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | $up->isa('PPI::Statement::Expression') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | or $up->isa('PPI::Structure::List') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | or $up->isa('PPI::Statement') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if (my $word = $up->sprevious_sibling) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # Since backslashes distribute over lists (per perlref), if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # we have a list and the previous is a backslash, we're cool. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | return if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | $up->isa('PPI::Structure::List') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$up->isa("PPI::Structure::List") and $word->isa("PPI::Token::Cast") and $word->content eq "\\"
$up->isa("PPI::Structure::List") and $word->isa("PPI::Token::Cast")
MC/DC0%0/3
$up->isa("PPI::Structure::List") and $word->isa("PPI::Token::Cast") and $word->content eq "\\"
$up->isa("PPI::Structure::List")
$word->isa("PPI::Token::Cast")
$word->content eq "\\"
Truth table0%0/4
A and B and C
A= $up->isa("PPI::Structure::List")B= $word->isa("PPI::Token::Cast")C= $word->content eq "\\"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | && $word->isa('PPI::Token::Cast') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | && $word->content() eq q{\\}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # For a word set $previous to have it checked against %EXEMPTIONS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # below. For a non-word it's a violation, leave $previous false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # to get there. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if ($word->isa('PPI::Token::Word')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | $previous = $word; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | last PARENT; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | return if $previous and $EXEMPTIONS{$previous}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$previous and $EXEMPTIONS{$previous}
MC/DC0%0/2
$previous and $EXEMPTIONS{$previous}
$previous
$EXEMPTIONS{$previous}
Truth table0%0/3
A and B
A= $previousB= $EXEMPTIONS{$previous}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | return $self->violation( $DESC, $EXPL, $elem ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 40 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||