« Policy/CodeLayout/RequireParensWithBuiltins.pm
↑ Summary
Policy/Variables/ProhibitExcessiveNames.pm »
| 1 | package Perl::Critic::Policy::ControlStructures::ProhibitInlineDo; | ||||||||||||||||||||||||||||
| 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{Do not use inline do-blocks}; | |||||||||||||||||||||||||||
| 14 | 11 | Readonly::Scalar my $EXPL => undef; # [ ]; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 12 | ▶ | sub applies_to { return 'PPI::Token::Word' } | ||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 4 | ▶ | sub default_severity { return $SEVERITY_LOW } | ||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | 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 | 7 | ▶ | sub _cmpLocation { | ||||||||||||||||||||||||||
|
Subroutine
_cmpLocation: called CC=6 SCAR=19.0
| |||||||||||||||||||||||||||||
| 26 | 7 | my ($L,$R)=@_; | |||||||||||||||||||||||||||
| 27 | 7 | ▶ | my @ll=@{$L->location()//[]}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$L->location // []
MC/DC0%0/1
$L->location // []
$L->location
Truth table50%1/2
A
A= $L->location
| |||||||||||||||||||||||||||||
| 28 | 7 | ▶ | my @rr=@{$R->location()//[]}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$R->location // []
MC/DC0%0/1
$R->location // []
$R->location
Truth table50%1/2
A
A= $R->location
| |||||||||||||||||||||||||||||
| 29 | 7 | ▶ | @ll or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 7 | ▶ | @rr or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 7 | ▶ | return ($ll[0]<=>$rr[0]) || ($ll[1]<=>$rr[1]); | ||||||||||||||||||||||||||
|
Condition66%2/3
$ll[0] <=> $rr[0] || $ll[1] <=> $rr[1]
MC/DC50%1/2
$ll[0] <=> $rr[0] || $ll[1] <=> $rr[1]
$ll[0] <=> $rr[0]
$ll[1] <=> $rr[1]
Truth table66%2/3
A || B
A= $ll[0] <=> $rr[0]B= $ll[1] <=> $rr[1]
| |||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 33 | ▶ | sub violates { | ||||||||||||||||||||||||||
|
Subroutine
violates: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 33 | my ($self,$elem,undef)=@_; | |||||||||||||||||||||||||||
| 36 | 33 | ▶ | if(!$elem->isa('PPI::Token::Word')) { return } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 32 | ▶ | if(!is_perl_bareword($elem)) { return } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 23 | ▶ | if(is_method_call($elem)) { return } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 22 | ▶ | if($elem->content() ne 'do') { return } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 14 | my $next=$elem->snext_sibling(); | |||||||||||||||||||||||||||
| 42 | 14 | ▶ | if(!$next || !$next->isa('PPI::Structure::Block')) { return } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$next and $next->isa("PPI::Structure::Block")
MC/DC100%2/2
$next and $next->isa("PPI::Structure::Block")
$next
$next->isa("PPI::Structure::Block")
Truth table100%3/3
A and B
A= $nextB= $next->isa("PPI::Structure::Block")
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 10 | my $parent=$elem->parent(); | |||||||||||||||||||||||||||
| 45 | 0 | ▶ | if(!$parent) { return $self->violation($DESC,$EXPL,$elem) } # impossible? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 10 | ▶ | if($parent->isa('PPI::Statement::Sub')) { return } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 7 | ▶ | if($parent->isa('PPI::Statement')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 7 | my $token=$parent->first_token(); | |||||||||||||||||||||||||||
| 49 | 7 | ▶ | if(0==_cmpLocation($elem,$token)) { return } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 4 | return $self->violation($DESC,$EXPL,$elem); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 11 | 1; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | __END__ | ||||||||||||||||||||||||||||