X-Git-Url: http://git.maemo.org/git/?p=dh-make-perl;a=blobdiff_plain;f=dev%2Farm%2Flibperl-critic-perl%2Flibperl-critic-perl-1.088%2Flib%2FPerl%2FCritic%2FPolicy%2FControlStructures%2FProhibitLabelsWithSpecialBlockNames.pm;fp=dev%2Farm%2Flibperl-critic-perl%2Flibperl-critic-perl-1.088%2Flib%2FPerl%2FCritic%2FPolicy%2FControlStructures%2FProhibitLabelsWithSpecialBlockNames.pm;h=13c6fa9d61eae31bab8cdafb3b7822d287a44c9b;hp=0000000000000000000000000000000000000000;hb=f477fa73365d491991707e7ed9217b48d6994551;hpb=da95c414033799c3a62606f299c3c00b5c77ca11 diff --git a/dev/arm/libperl-critic-perl/libperl-critic-perl-1.088/lib/Perl/Critic/Policy/ControlStructures/ProhibitLabelsWithSpecialBlockNames.pm b/dev/arm/libperl-critic-perl/libperl-critic-perl-1.088/lib/Perl/Critic/Policy/ControlStructures/ProhibitLabelsWithSpecialBlockNames.pm new file mode 100644 index 0000000..13c6fa9 --- /dev/null +++ b/dev/arm/libperl-critic-perl/libperl-critic-perl-1.088/lib/Perl/Critic/Policy/ControlStructures/ProhibitLabelsWithSpecialBlockNames.pm @@ -0,0 +1,124 @@ +############################################################################## +# $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/lib/Perl/Critic/Policy/ControlStructures/ProhibitLabelsWithSpecialBlockNames.pm $ +# $Date: 2008-07-03 10:19:10 -0500 (Thu, 03 Jul 2008) $ +# $Author: clonezone $ +# $Revision: 2489 $ +############################################################################## + +package Perl::Critic::Policy::ControlStructures::ProhibitLabelsWithSpecialBlockNames; + +use 5.006001; +use strict; +use warnings; + +use Readonly; + +use Perl::Critic::Utils qw{ :severities hashify }; +use base 'Perl::Critic::Policy'; + +our $VERSION = '1.088'; + +Readonly::Hash my %SPECIAL_BLOCK_NAMES => + hashify( qw< BEGIN END INIT CHECK UNITCHECK > ); + +#----------------------------------------------------------------------------- + +Readonly::Scalar my $DESC => q; +Readonly::Scalar my $EXPL => + q; + +#----------------------------------------------------------------------------- + +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 > } + +#----------------------------------------------------------------------------- + +sub violates { + my ($self, $elem, undef) = @_; + + # Does the function call have enough arguments? + my $label = $elem->content(); + $label =~ s/ \s* : \z //xms; + return if not $SPECIAL_BLOCK_NAMES{ $label }; + + return $self->violation( $DESC, $EXPL, $elem ); +} + + +1; + +#----------------------------------------------------------------------------- + +__END__ + +=for stopwords Lauen O'Regan + +=pod + +=head1 NAME + +Perl::Critic::Policy::ControlStructures::ProhibitLabelsWithSpecialBlockNames - Don't use labels that are the same as the special block names. + + +=head1 AFFILIATION + +This Policy is part of the core L distribution. + + +=head1 DESCRIPTION + +When using one of the special Perl blocks C, C, C, +C, and C, 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. + + +=head1 CONFIGURATION + +This Policy is not configurable except for the standard options. + + +=head1 SEE ALSO + +L +on this issue. + + +=head1 ACKNOWLEDGMENT + +Randy Lauen for identifying the problem. + + +=head1 AUTHOR + +Mike O'Regan + + +=head1 COPYRIGHT + +Copyright (c) 2008 Mike O'Regan. All rights reserved. + +This program is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +# Local Variables: +# mode: cperl +# cperl-indent-level: 4 +# fill-column: 78 +# indent-tabs-mode: nil +# c-indentation-style: bsd +# End: +# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :