« lib/Perl/Critic/Policy/Modules/RequireNoMatchVarsWithUseEnglish.pm
↑ Summary
lib/Perl/Critic/Policy/BuiltinFunctions/ProhibitStringyEval.pm »
| 1 | package Perl::Critic::Policy::BuiltinFunctions::ProhibitComplexMappings; | ||||||||||||||||||||||||||||
| 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 | 40 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 40 | ▶ | use Perl::Critic::Utils qw{ :severities :classification }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 40 | ▶ | use parent 'Perl::Critic::Policy'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 40 | our $VERSION = '1.156'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 40 | Readonly::Scalar my $DESC => q{Map blocks should have a single statement}; | |||||||||||||||||||||||||||
| 16 | 40 | Readonly::Scalar my $EXPL => [ 113 ]; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 91 | ▶ | sub supported_parameters { | ||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 21 | return ( | ||||||||||||||||||||||||||||
| 22 | { | ||||||||||||||||||||||||||||
| 23 | 91 | name => 'max_statements', | |||||||||||||||||||||||||||
| 24 | description => | ||||||||||||||||||||||||||||
| 25 | 'The maximum number of statements to allow within a map block.', | ||||||||||||||||||||||||||||
| 26 | default_string => '1', | ||||||||||||||||||||||||||||
| 27 | behavior => 'integer', | ||||||||||||||||||||||||||||
| 28 | integer_minimum => 1, | ||||||||||||||||||||||||||||
| 29 | }, | ||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 74 | ▶ | sub default_severity { return $SEVERITY_MEDIUM } | ||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | 85 | ▶ | sub default_themes { return qw( core pbp maintenance complexity) } | ||||||||||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 31 | ▶ | sub applies_to { return 'PPI::Token::Word' } | ||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 332 | ▶ | sub violates { | ||||||||||||||||||||||||||
|
Subroutine
violates: called CC=11 SCAR=46.5
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | 332 | my ( $self, $elem, undef ) = @_; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 332 | ▶ | return if $elem->content() ne 'map'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | return if ! is_function_call($elem); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | my $sib = $elem->snext_sibling(); | |||||||||||||||||||||||||||
| 46 | 0 | ▶ | return if !$sib; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | my $arg = $sib; | |||||||||||||||||||||||||||
| 49 | 0 | ▶ | if ( $arg->isa('PPI::Structure::List') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | $arg = $arg->schild(0); | |||||||||||||||||||||||||||
| 51 | # Forward looking: PPI might change in v1.200 so schild(0) is a PPI::Statement::Expression | ||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if ( $arg && $arg->isa('PPI::Statement::Expression') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$arg and $arg->isa("PPI::Statement::Expression")
MC/DC0%0/2
$arg and $arg->isa("PPI::Statement::Expression")
$arg
$arg->isa("PPI::Statement::Expression")
Truth table0%0/3
A and B
A= $argB= $arg->isa("PPI::Statement::Expression")
| |||||||||||||||||||||||||||||
| 53 | 0 | $arg = $arg->schild(0); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | # If it's not a block, it's an expression-style map, which is only one statement by definition | ||||||||||||||||||||||||||||
| 57 | 0 | ▶ | return if !$arg; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | return if !$arg->isa('PPI::Structure::Block'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # If we get here, we found a sort with a block as the first arg | ||||||||||||||||||||||||||||
| 61 | return if $self->{_max_statements} >= $arg->schildren() | ||||||||||||||||||||||||||||
| 62 | 0 | ▶ | && 0 == grep {$_->isa('PPI::Statement::Compound')} $arg->schildren(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"_max_statements"} >= $arg->schildren and 0 == grep({$_->isa("PPI::Statement::Compound");} $arg->schildren)
MC/DC0%0/2
$self->{"_max_statements"} >= $arg->schildren and 0 == grep({$_->isa("PPI::Statement::Compound");} $arg->schildren)
$self->{"_max_statements"} >= $arg->schildren
0 == grep({$_->isa("PPI::Statement::Compound");} $arg->schildren)
Truth table0%0/3
A and B
A= $self->{"_max_statements"} >= $arg->schildrenB= 0 == grep({$_->isa("PPI::Statement::Compound");} $arg->schildren)
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | # more than one child statements | ||||||||||||||||||||||||||||
| 65 | 0 | return $self->violation( $DESC, $EXPL, $elem ); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 40 | 1; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | __END__ | ||||||||||||||||||||||||||||