« lib/Perl/Critic/Policy/RegularExpressions/RequireBracesForMultiline.pm
↑ Summary
lib/Perl/Critic/Policy/ValuesAndExpressions/RequireNumberSeparators.pm »
| 1 | package Perl::Critic::Policy::ControlStructures::ProhibitDeepNests; | ||||||||||
| 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 }; | ||||||||
|
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{Code structure is deeply nested}; | |||||||||
| 16 | 40 | Readonly::Scalar my $EXPL => q{Consider refactoring}; | |||||||||
| 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_nests', | |||||||||
| 24 | description => 'The maximum number of nested constructs to allow.', | ||||||||||
| 25 | default_string => '5', | ||||||||||
| 26 | behavior => 'integer', | ||||||||||
| 27 | integer_minimum => 1, | ||||||||||
| 28 | }, | ||||||||||
| 29 | ); | ||||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 74 | ▶ | sub default_severity { return $SEVERITY_MEDIUM } | ||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 33 | 73 | ▶ | sub default_themes { return qw(core maintenance complexity) } | ||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 34 | 31 | ▶ | sub applies_to { return 'PPI::Statement::Compound' } | ||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 35 | |||||||||||
| 36 | #----------------------------------------------------------------------------- | ||||||||||
| 37 | |||||||||||
| 38 | 11 | ▶ | sub violates { | ||||||||
|
Subroutine
violates: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||
| 39 | 11 | my ( $self, $elem, undef ) = @_; | |||||||||
| 40 | |||||||||||
| 41 | 11 | my $nest_count = 1; #For _this_ element | |||||||||
| 42 | 11 | my $parent = $elem; | |||||||||
| 43 | |||||||||||
| 44 | 11 | ▶ | while ( $parent = $parent->parent() ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 11 | ▶ | if( $parent->isa('PPI::Statement::Compound') ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 0 | $nest_count++; | |||||||||
| 47 | } | ||||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 11 | ▶ | if ( $nest_count > $self->{_max_nests} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 0 | return $self->violation( $DESC, $EXPL, $elem ); | |||||||||
| 52 | } | ||||||||||
| 53 | 11 | return; #ok! | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | |||||||||||
| 57 | 40 | 1; | |||||||||
| 58 | |||||||||||
| 59 | __END__ | ||||||||||