| 1 | package Perl::Critic::Policy::Variables::ProhibitTopicIterator; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use 5.010001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use Perl::Critic::Utils qw/:severities :classification/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use base 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 11 | our $VERSION = '0.1.4'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 11 | Readonly::Scalar my $DESC => q{Always use named loop control variables}; | |||||||||||||||||||||||||||
| 14 | 11 | Readonly::Scalar my $EXPL => undef; # [ ]; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 28 | ▶ | sub applies_to { return 'PPI::Statement::Compound' } | ||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 8 | ▶ | sub default_severity { return $SEVERITY_LOW } | ||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 2 | ▶ | sub default_themes { return qw/maintenance complexity/ } | ||||||||||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | 2 | ▶ | sub supported_parameters { return } | ||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 24 | ▶ | sub violates { | ||||||||||||||||||||||||||
|
Subroutine
violates: called CC=16 SCAR=30.3
Pod
documented
| |||||||||||||||||||||||||||||
| 26 | 24 | my ($self,$elem,undef)=@_; | |||||||||||||||||||||||||||
| 27 | 0 | ▶ | if(!$elem->isa('PPI::Statement::Compound')) { return } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 24 | my $node=$elem->first_element(); | |||||||||||||||||||||||||||
| 29 | 0 | ▶ | if(!$node->isa('PPI::Token::Word')) { return } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 24 | my $type=$node->content(); | |||||||||||||||||||||||||||
| 31 | 24 | my $next=$node->snext_sibling(); | |||||||||||||||||||||||||||
| 32 | 0 | ▶ | if(!$next) { return } # invalid syntax? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | # | ||||||||||||||||||||||||||||
| 34 | 24 | ▶ | if($type=~/^for(?:each)?$/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 35 | 18 | ▶ | if($next->isa('PPI::Structure::List')) { return $self->violation($DESC,$EXPL,$elem) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 16 | ▶ | if($next->isa('PPI::Token::Magic')&&($next->content() eq '$_')) { return $self->violation($DESC,$EXPL,$elem) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$next->isa("PPI::Token::Magic") and $next->content eq "\$_"
MC/DC50%1/2
$next->isa("PPI::Token::Magic") and $next->content eq "\$_"
$next->isa("PPI::Token::Magic")
$next->content eq "\$_"
Truth table66%2/3
A and B
A= $next->isa("PPI::Token::Magic")B= $next->content eq "\$_"
| |||||||||||||||||||||||||||||
| 37 | 14 | ▶ | if($next->isa('PPI::Structure::For')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 6 | ▶ | if($next->find_first(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=19.5
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 36 | my (undef,$e)=@_; | |||||||||||||||||||||||||||
| 40 | 36 | ▶ | if(!$e->isa('PPI::Token::Magic')) { return 0 } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if($e->content() ne '$_') { return 0 } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 2 | my $ne=$e->snext_sibling(); | |||||||||||||||||||||||||||
| 43 | 0 | ▶ | if(!$ne) { return 0 } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if(!$ne->isa('PPI::Token::Operator')) { return 0 } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if($ne->content() ne '=') { return 0 } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 2 | return 1; | |||||||||||||||||||||||||||
| 47 | 2 | })) { return $self->violation($DESC,$EXPL,$elem) } | |||||||||||||||||||||||||||
| 48 | 4 | return; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | 8 | ▶ | if($next->isa('PPI::Token::Symbol')) { return } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 4 | ▶ | if($next->isa('PPI::Token::Word')&&($next->content() eq 'my')) { return } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$next->isa("PPI::Token::Word") and $next->content eq "my"
MC/DC0%0/2
$next->isa("PPI::Token::Word") and $next->content eq "my"
$next->isa("PPI::Token::Word")
$next->content eq "my"
Truth table33%1/3
A and B
A= $next->isa("PPI::Token::Word")B= $next->content eq "my"
| |||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | ▶ | elsif(($type=~/^(?:if|while)$/)&&$next->isa('PPI::Structure::Condition')) { | |||||||||||||||||||||||||||
|
Condition33%1/3
$type =~ /^(?:if|while)$/ and $next->isa("PPI::Structure::Condition")
MC/DC0%0/2
$type =~ /^(?:if|while)$/ and $next->isa("PPI::Structure::Condition")
$type =~ /^(?:if|while)$/
$next->isa("PPI::Structure::Condition")
Truth table33%1/3
A and B
A= $type =~ /^(?:if|while)$/B= $next->isa("PPI::Structure::Condition")
| |||||||||||||||||||||||||||||
| 54 | 6 | ▶ | if($next->find_first(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.6
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 32 | my (undef,$e)=@_; | |||||||||||||||||||||||||||
| 56 | 32 | ▶ | if(!$e->isa('PPI::Token::Magic')) { return 0 } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if($e->content() ne '$_') { return 0 } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 3 | my $ne=$e->snext_sibling(); | |||||||||||||||||||||||||||
| 59 | 0 | ▶ | if(!$ne) { return 0 } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if(!$ne->isa('PPI::Token::Operator')) { return 0 } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 3 | ▶ | if($ne->content() ne '=') { return 0 } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 2 | return 1; | |||||||||||||||||||||||||||
| 63 | 2 | })) { return $self->violation($DESC,$EXPL,$elem) } | |||||||||||||||||||||||||||
| 64 | 4 | return; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | 0 | return; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 11 | 1; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | __END__ | ||||||||||||||||||||||||||||