« lib/Perl/Critic/Policy/ValuesAndExpressions/RequireInterpolationOfMetachars.pm
↑ Summary
lib/Perl/Critic/Policy/NamingConventions/Capitalization.pm »
| 1 | package Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls; | ||||||||||||||||||||||||||||
| 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{ :characters :severities :data_conversion :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::Hash my %PAGES_OF => ( | |||||||||||||||||||||||||||
| 16 | if => [ 93, 94 ], | ||||||||||||||||||||||||||||
| 17 | unless => [ 96, 97 ], | ||||||||||||||||||||||||||||
| 18 | until => [ 96, 97 ], | ||||||||||||||||||||||||||||
| 19 | for => [ 96 ], | ||||||||||||||||||||||||||||
| 20 | foreach => [ 96 ], | ||||||||||||||||||||||||||||
| 21 | while => [ 96 ], | ||||||||||||||||||||||||||||
| 22 | when => q<Similar to "if", postfix "when" should only be used with flow-control>, | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 92 | ▶ | sub supported_parameters { | ||||||||||||||||||||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 28 | return ( | ||||||||||||||||||||||||||||
| 29 | { | ||||||||||||||||||||||||||||
| 30 | 92 | name => 'allow', | |||||||||||||||||||||||||||
| 31 | description => 'The permitted postfix controls.', | ||||||||||||||||||||||||||||
| 32 | default_string => $EMPTY, | ||||||||||||||||||||||||||||
| 33 | behavior => 'enumeration', | ||||||||||||||||||||||||||||
| 34 | enumeration_values => [ sort keys %PAGES_OF ], | ||||||||||||||||||||||||||||
| 35 | enumeration_allow_multiple_values => 1, | ||||||||||||||||||||||||||||
| 36 | }, | ||||||||||||||||||||||||||||
| 37 | { | ||||||||||||||||||||||||||||
| 38 | name => 'flowcontrol', | ||||||||||||||||||||||||||||
| 39 | description => 'The exempt flow control functions.', | ||||||||||||||||||||||||||||
| 40 | default_string => 'carp cluck confess croak die exit goto warn', | ||||||||||||||||||||||||||||
| 41 | behavior => 'string list', | ||||||||||||||||||||||||||||
| 42 | }, | ||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 92 | ▶ | sub default_severity { return $SEVERITY_LOW } | ||||||||||||||||||||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | 83 | ▶ | sub default_themes { return qw(core pbp cosmetic) } | ||||||||||||||||||||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 48 | 31 | ▶ | sub applies_to { return 'PPI::Token::Word' } | ||||||||||||||||||||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 332 | ▶ | sub violates { | ||||||||||||||||||||||||||
|
Subroutine
violates: called CC=15 SCAR=28.7
Pod
documented
| |||||||||||||||||||||||||||||
| 53 | 332 | my ( $self, $elem, undef ) = @_; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 332 | my $expl = $PAGES_OF{$elem}; | |||||||||||||||||||||||||||
| 56 | 332 | ▶ | return if not $expl; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 29 | ▶ | return if is_hash_key($elem); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 29 | ▶ | return if is_method_call($elem); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 29 | ▶ | return if is_subroutine_name($elem); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 29 | ▶ | return if is_included_module_name($elem); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 29 | ▶ | return if is_package_declaration($elem); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | # Skip controls that are allowed | ||||||||||||||||||||||||||||
| 65 | 29 | ▶ | return if exists $self->{_allow}->{ $elem->content() }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # Skip Compound variety (these are good) | ||||||||||||||||||||||||||||
| 68 | 29 | my $stmnt = $elem->statement(); | |||||||||||||||||||||||||||
| 69 | 29 | ▶ | return if not $stmnt; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 29 | ▶ | return if $stmnt->isa('PPI::Statement::Compound'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 19 | ▶ | return if $stmnt->isa('PPI::Statement::When'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # Handle special cases | ||||||||||||||||||||||||||||
| 74 | 19 | my $content = $elem->content(); | |||||||||||||||||||||||||||
| 75 | 19 | ▶ | if ($content eq 'if' or $content eq 'when') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$content eq "if" or $content eq "when"
MC/DC50%1/2
$content eq "if" or $content eq "when"
$content eq "if"
$content eq "when"
Truth table66%2/3
A or B
A= $content eq "if"B= $content eq "when"
| |||||||||||||||||||||||||||||
| 76 | # Postfix 'if' allowed with loop breaks, or other | ||||||||||||||||||||||||||||
| 77 | # flow-controls like 'die', 'warn', and 'croak' | ||||||||||||||||||||||||||||
| 78 | 3 | ▶ | return if $stmnt->isa('PPI::Statement::Break'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 3 | ▶ | return if defined $self->{_flowcontrol}{ $stmnt->schild(0)->content() }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | # If we get here, it must be postfix. | ||||||||||||||||||||||||||||
| 83 | 19 | my $desc = qq{Postfix control "$content" used}; | |||||||||||||||||||||||||||
| 84 | 19 | return $self->violation($desc, $expl, $elem); | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 40 | 1; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | __END__ | ||||||||||||||||||||||||||||