« lib/Perl/Critic/Policy/ValuesAndExpressions/ProhibitSpecialLiteralHeredocTerminator.pm
↑ Summary
lib/Perl/Critic/Policy/BuiltinFunctions/RequireGlobFunction.pm »
| 1 | package Perl::Critic::Policy::ControlStructures::ProhibitLabelsWithSpecialBlockNames; | ||||||||||
| 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 | |||||||||||
| 7 | 40 | ▶ | use Readonly; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 40 | ▶ | use Perl::Critic::Utils qw{ :severities hashify }; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 40 | ▶ | use parent 'Perl::Critic::Policy'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 40 | our $VERSION = '1.156'; | |||||||||
| 13 | |||||||||||
| 14 | 40 | Readonly::Hash my %SPECIAL_BLOCK_NAMES => | |||||||||
| 15 | hashify( qw< BEGIN END INIT CHECK UNITCHECK > ); | ||||||||||
| 16 | |||||||||||
| 17 | #----------------------------------------------------------------------------- | ||||||||||
| 18 | |||||||||||
| 19 | 40 | Readonly::Scalar my $DESC => q<Special block name used as label.>; | |||||||||
| 20 | 40 | Readonly::Scalar my $EXPL => | |||||||||
| 21 | q<Use a label that cannot be confused with BEGIN, END, CHECK, INIT, or UNITCHECK blocks.>; | ||||||||||
| 22 | |||||||||||
| 23 | #----------------------------------------------------------------------------- | ||||||||||
| 24 | |||||||||||
| 25 | 90 | ▶ | sub supported_parameters { return () } | ||||||||
|
Subroutine
supported_parameters: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 26 | 74 | ▶ | sub default_severity { return $SEVERITY_HIGH } | ||||||||
|
Subroutine
default_severity: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 27 | 73 | ▶ | sub default_themes { return qw< core bugs > } | ||||||||
|
Subroutine
default_themes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 28 | 33 | ▶ | sub applies_to { return qw< PPI::Token::Label > } | ||||||||
|
Subroutine
applies_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 29 | |||||||||||
| 30 | #----------------------------------------------------------------------------- | ||||||||||
| 31 | |||||||||||
| 32 | 0 | ▶ | sub violates { | ||||||||
|
Subroutine
violates: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 33 | 0 | my ($self, $elem, undef) = @_; | |||||||||
| 34 | |||||||||||
| 35 | # Does the function call have enough arguments? | ||||||||||
| 36 | 0 | my $label = $elem->content(); | |||||||||
| 37 | 0 | $label =~ s/ \s* : \z //xms; | |||||||||
| 38 | 0 | ▶ | return if not $SPECIAL_BLOCK_NAMES{ $label }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | |||||||||||
| 40 | 0 | return $self->violation( $DESC, $EXPL, $elem ); | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | |||||||||||
| 44 | 40 | 1; | |||||||||
| 45 | |||||||||||
| 46 | #----------------------------------------------------------------------------- | ||||||||||
| 47 | |||||||||||
| 48 | __END__ | ||||||||||