« lib/Perl/Critic/Policy/Variables/ProhibitPunctuationVars.pm
↑ Summary
lib/Perl/Critic/Policy/Documentation/PodSpelling.pm »
| 1 | package Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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{ :booleans :severities hashify }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
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{Conditional "use" statement}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 40 | Readonly::Scalar my $EXPL => q{Use "require" to conditionally include a module.}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # operators | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 40 | Readonly::Hash my %OPS => hashify( qw( || && or and ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 90 | ▶ | sub supported_parameters { return () } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 74 | ▶ | sub default_severity { return $SEVERITY_MEDIUM } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 73 | ▶ | sub default_themes { return qw( core bugs ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 31 | ▶ | sub applies_to { return 'PPI::Statement::Include' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 57 | ▶ | sub violates { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
violates: called CC=5 SCAR=16.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 57 | my ( $self, $elem, undef ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 57 | ▶ | return $self->violation( $DESC, $EXPL, $elem ) if $elem->type() eq 'use' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
$elem->type eq "use" and not $elem->pragma and $elem->module and _is_in_conditional_logic($elem)
$elem->type eq "use" and not $elem->pragma and $elem->module
$elem->type eq "use" and not $elem->pragma
MC/DC0%0/4
$elem->type eq "use" and not $elem->pragma and $elem->module and _is_in_conditional_logic($elem)
$elem->type eq "use"
not $elem->pragma
$elem->module
_is_in_conditional_logic($elem)
Truth table60%3/5
A and not(B) and C and D
A= $elem->type eq "use"B= not $elem->pragmaC= $elem->moduleD= _is_in_conditional_logic($elem)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | && !$elem->pragma() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | && $elem->module() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | && _is_in_conditional_logic($elem); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 57 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # is this a non-string eval statement | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub _is_eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_eval: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | my ( $elem ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | $elem->isa('PPI::Statement') or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $first_elem = $elem->first_element(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | return $TRUE if $first_elem->isa('PPI::Token::Word') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$first_elem->isa("PPI::Token::Word") and $first_elem eq "eval"
MC/DC0%0/2
$first_elem->isa("PPI::Token::Word") and $first_elem eq "eval"
$first_elem->isa("PPI::Token::Word")
$first_elem eq "eval"
Truth table0%0/3
A and B
A= $first_elem->isa("PPI::Token::Word")B= $first_elem eq "eval"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | && $first_elem eq 'eval'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # is this in a conditional do block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub _is_in_do_conditional_block { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_in_do_conditional_block: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | my ( $elem ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | return if !$elem->isa('PPI::Structure::Block'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | my $prev_sibling = $elem->sprevious_sibling() or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if ($prev_sibling->isa('PPI::Token::Word') && $prev_sibling eq 'do') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$prev_sibling->isa("PPI::Token::Word") and $prev_sibling eq "do"
MC/DC0%0/2
$prev_sibling->isa("PPI::Token::Word") and $prev_sibling eq "do"
$prev_sibling->isa("PPI::Token::Word")
$prev_sibling eq "do"
Truth table0%0/3
A and B
A= $prev_sibling->isa("PPI::Token::Word")B= $prev_sibling eq "do"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $next_sibling = $elem->snext_sibling(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | return $TRUE if $next_sibling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$next_sibling and $next_sibling->isa("PPI::Token::Word")
MC/DC0%0/2
$next_sibling and $next_sibling->isa("PPI::Token::Word")
$next_sibling
$next_sibling->isa("PPI::Token::Word")
Truth table0%0/3
A and B
A= $next_siblingB= $next_sibling->isa("PPI::Token::Word")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | && $next_sibling->isa('PPI::Token::Word'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | $prev_sibling = $prev_sibling->sprevious_sibling() or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | return $TRUE if $prev_sibling->isa('PPI::Token::Operator') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | && $OPS{$prev_sibling->content()}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$prev_sibling->isa("PPI::Token::Operator") and $OPS{$prev_sibling->content}
MC/DC0%0/2
$prev_sibling->isa("PPI::Token::Operator") and $OPS{$prev_sibling->content}
$prev_sibling->isa("PPI::Token::Operator")
$OPS{$prev_sibling->content}
Truth table0%0/3
A and B
A= $prev_sibling->isa("PPI::Token::Operator")B= $OPS{$prev_sibling->content}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # is this a compound statement | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub _is_compound_statement { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_compound_statement: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my ( $elem ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | return if !$elem->isa('PPI::Statement::Compound'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | return $TRUE if $elem->type() ne 'continue'; # exclude bare blocks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # is this contained in conditional logic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | ▶ | sub _is_in_conditional_logic { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_in_conditional_logic: called CC=6 SCAR=27.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | my ( $elem ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | ▶ | while ($elem = $elem->parent()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | ▶ | last if $elem->isa('PPI::Document'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | return $TRUE if _is_compound_statement($elem) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
_is_compound_statement($elem) or _is_eval($elem) or _is_in_do_conditional_block($elem)
_is_compound_statement($elem) or _is_eval($elem)
MC/DC0%0/3
_is_compound_statement($elem) or _is_eval($elem) or _is_in_do_conditional_block($elem)
_is_compound_statement($elem)
_is_eval($elem)
_is_in_do_conditional_block($elem)
Truth table0%0/4
A or B or C
A= _is_compound_statement($elem)B= _is_eval($elem)C= _is_in_do_conditional_block($elem)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | || _is_eval($elem) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | || _is_in_do_conditional_block($elem); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 40 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||