Benchmark-Perl-Formance-Cargo

 view release on metacpan or  search on metacpan

share/PerlCritic/Critic/Policy/ControlStructures/ProhibitLabelsWithSpecialBlockNames.pm  view on Meta::CPAN

use warnings;

use Readonly;

use Perl::Critic::Utils qw{ :severities hashify };
use base 'Perl::Critic::Policy';

our $VERSION = '1.108';

Readonly::Hash my %SPECIAL_BLOCK_NAMES =>
    hashify( qw< BEGIN END INIT CHECK UNITCHECK > );

#-----------------------------------------------------------------------------

Readonly::Scalar my $DESC => q<Special block name used as label.>;
Readonly::Scalar my $EXPL =>
    q<Use a label that cannot be confused with BEGIN, END, CHECK, INIT, or UNITCHECK blocks.>;

#-----------------------------------------------------------------------------

sub supported_parameters { return ()                      }
sub default_severity     { return $SEVERITY_HIGH          }
sub default_themes       { return qw< core bugs >         }
sub applies_to           { return qw< PPI::Token::Label > }

#-----------------------------------------------------------------------------

share/PerlCritic/Critic/Policy/ControlStructures/ProhibitLabelsWithSpecialBlockNames.pm  view on Meta::CPAN


=head1 AFFILIATION

This Policy is part of the core L<Perl::Critic|Perl::Critic>
distribution.


=head1 DESCRIPTION

When using one of the special Perl blocks C<BEGIN>, C<END>, C<CHECK>,
C<INIT>, and C<UNITCHECK>, it is easy to mistakenly add a colon to the
end of the block name.  E.g.:

    # a BEGIN block that gets executed at compile time.
    BEGIN { <...code...> }

    # an ordinary labeled block that gets executed at run time.
    BEGIN: { <...code...> }

The labels "BEGIN:", "END:", etc. are probably errors.  This policy
prohibits the special Perl block names from being used as labels.



( run in 0.666 second using v1.01-cache-2.11-cpan-702932259ff )