« lib/Perl/Critic/Policy/InputOutput/ProhibitBarewordFileHandles.pm
↑ Summary
lib/Perl/Critic/Policy/RegularExpressions/ProhibitComplexRegexes.pm »
| 1 | package Perl::Critic::Policy::BuiltinFunctions::RequireSimpleSortBlock; | ||||||||||||||||||||||||||||
| 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{Sort blocks should have a single statement}; | |||||||||||||||||||||||||||
| 16 | 40 | Readonly::Scalar my $EXPL => [ 149 ]; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 90 | ▶ | sub supported_parameters { return () } | ||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 21 | 74 | ▶ | sub default_severity { return $SEVERITY_MEDIUM } | ||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 22 | 85 | ▶ | sub default_themes { return qw( core pbp maintenance complexity) } | ||||||||||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 31 | ▶ | sub applies_to { return 'PPI::Token::Word' } | ||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 332 | ▶ | sub violates { | ||||||||||||||||||||||||||
|
Subroutine
violates: called CC=10 SCAR=44.4
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | 332 | my ( $self, $elem, undef ) = @_; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 332 | ▶ | return if $elem->content() ne 'sort'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | return if ! is_function_call($elem); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | my $sib = $elem->snext_sibling(); | |||||||||||||||||||||||||||
| 34 | 0 | ▶ | return if !$sib; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | my $arg = $sib; | |||||||||||||||||||||||||||
| 37 | 0 | ▶ | if ( $arg->isa('PPI::Structure::List') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 0 | $arg = $arg->schild(0); | |||||||||||||||||||||||||||
| 39 | # Forward looking: PPI might change in v1.200 so schild(0) is a PPI::Statement::Expression | ||||||||||||||||||||||||||||
| 40 | 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")
| |||||||||||||||||||||||||||||
| 41 | 0 | $arg = $arg->schild(0); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | 0 | ▶ | return if !$arg || !$arg->isa('PPI::Structure::Block'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$arg and $arg->isa("PPI::Structure::Block")
MC/DC0%0/2
$arg and $arg->isa("PPI::Structure::Block")
$arg
$arg->isa("PPI::Structure::Block")
Truth table0%0/3
A and B
A= $argB= $arg->isa("PPI::Structure::Block")
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | # If we get here, we found a sort with a block as the first arg | ||||||||||||||||||||||||||||
| 47 | 0 | ▶ | return if ( 1 >= $arg->schildren() ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | # more than one child statements | ||||||||||||||||||||||||||||
| 50 | 0 | return $self->violation( $DESC, $EXPL, $elem ); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 40 | 1; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | __END__ | ||||||||||||||||||||||||||||