« lib/Perl/Critic/Policy/RegularExpressions/RequireExtendedFormatting.pm
↑ Summary
lib/Perl/Critic/Config.pm »
| 1 | package Perl::Critic::Policy::Variables::ProhibitConditionalDeclarations; | ||||||||||
| 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 :data_conversion }; | ||||||||
|
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{Variable declared in conditional statement}; | |||||||||
| 16 | 40 | Readonly::Scalar my $EXPL => q{Declare variables outside of the condition}; | |||||||||
| 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_HIGHEST } | ||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 22 | 73 | ▶ | sub default_themes { return qw( core bugs ) } | ||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 23 | 37 | ▶ | sub applies_to { return 'PPI::Statement::Variable' } | ||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 24 | |||||||||||
| 25 | #----------------------------------------------------------------------------- | ||||||||||
| 26 | |||||||||||
| 27 | 93 | ▶ | sub violates { | ||||||||
|
Subroutine
violates: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||
| 28 | 93 | my ( $self, $elem, undef ) = @_; | |||||||||
| 29 | 93 | ▶ | return if $elem->type() eq 'local'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | |||||||||||
| 31 | 93 | ▶ | if ( $elem->find(\&_is_conditional) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 0 | return $self->violation( $DESC, $EXPL, $elem ); | |||||||||
| 33 | } | ||||||||||
| 34 | 93 | return; #ok! | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 40 | my @conditionals = qw( if while foreach for until unless ); | |||||||||
| 38 | 40 | my %conditionals = hashify( @conditionals ); | |||||||||
| 39 | |||||||||||
| 40 | 744 | ▶ | sub _is_conditional { | ||||||||
|
Subroutine
_is_conditional: called CC=5 SCAR=28.4
| |||||||||||
| 41 | 744 | my (undef, $elem) = @_; | |||||||||
| 42 | |||||||||||
| 43 | 744 | ▶ | return if !$conditionals{$elem}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | ▶ | return if ! $elem->isa('PPI::Token::Word'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 0 | ▶ | return if is_hash_key($elem); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 0 | ▶ | return if is_method_call($elem); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | |||||||||||
| 48 | 0 | return 1; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 40 | 1; | |||||||||
| 52 | |||||||||||
| 53 | __END__ | ||||||||||