| 1 | package Perl::Critic::Policy::ValuesAndExpressions::ProhibitEmptyPostfixLoop; | ||||||||||||||||||||||||||||
| 2 | 2 | our $AUTHORITY = 'cpan:XSAWYERX'; | |||||||||||||||||||||||||||
| 3 | # ABSTRACT: Prohibit writing an postfix loop with no statement | ||||||||||||||||||||||||||||
| 4 | 2 | $Perl::Critic::Policy::ValuesAndExpressions::ProhibitEmptyPostfixLoop::VERSION = '0.001'; | |||||||||||||||||||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use parent 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Perl::Critic::Utils qw(:severities :classification :ppi); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use List::Util qw< first >; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use constant 'DESC' => 'Loop with no statement body'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use constant 'EXPL' => 'You wrote a postix loop but did not ' | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | . 'write a body for it. Maybe you accidentally ' | ||||||||||||||||||||||||||||
| 15 | 2 | . 'terminated the previous line?'; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 13 | ▶ | sub supported_parameters { () } | ||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 18 | 20 | ▶ | sub default_severity {$SEVERITY_HIGH} | ||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | sub default_themes {'bugs'} | ||||||||||||||||||||||||||
|
Subroutine
default_themes: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 13 | ▶ | sub applies_to {'PPI::Token::Word'} | ||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 53 | ▶ | sub violates { | ||||||||||||||||||||||||||
|
Subroutine
violates: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 53 | my ( $self, $elem ) = @_; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 53 | ▶ | first { $elem eq $_ } qw< for foreach > | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | or return (); | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # Don't be fooled by 'for' being used in a hash or somesuch | ||||||||||||||||||||||||||||
| 29 | 26 | ▶ | $elem->parent && $elem->parent->isa('PPI::Statement::Expression') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$elem->parent and $elem->parent->isa("PPI::Statement::Expression")
MC/DC0%0/2
$elem->parent and $elem->parent->isa("PPI::Statement::Expression")
$elem->parent
$elem->parent->isa("PPI::Statement::Expression")
Truth table33%1/3
A and B
A= $elem->parentB= $elem->parent->isa("PPI::Statement::Expression")
| |||||||||||||||||||||||||||||
| 30 | and return (); | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | # Detect if this is postfix or not by looking for a block | ||||||||||||||||||||||||||||
| 33 | 26 | my $next = $elem; | |||||||||||||||||||||||||||
| 34 | 26 | ▶ | while ( $next = $next->snext_sibling ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 16 | ▶ | $next->isa('PPI::Structure::Block') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | and return (); | ||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # Make sure this isn't a correct postfix loop | ||||||||||||||||||||||||||||
| 40 | $elem->sprevious_sibling | ||||||||||||||||||||||||||||
| 41 | 23 | ▶ | and return (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 20 | return $self->violation( DESC(), EXPL(), $elem ); | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 2 | 1; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | __END__ | ||||||||||||||||||||||||||||