package Perl::Critic::Policy::ControlStructures::ProhibitGotoLabel; use warnings; use strict; use base 'Perl::Critic::Policy'; use Perl::Critic::Utils qw/:severities/; # to locate the path where to place this file, do e.g.: # $ perl -MFile::Basename=dirname -MPerl::Critic::Policy::ControlStructures::ProhibitUnreachableCode -le 'print dirname $INC{"Perl/Critic/Policy/ControlStructures/ProhibitUnreachableCode.pm"}' # or # $ dirname `perldoc -l Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode` our $VERSION = '0.001'; sub supported_parameters { return } sub default_severity { return $SEVERITY_MEDIUM } sub default_themes { return qw/core bugs/ } sub applies_to { return 'PPI::Token::Word' } =head1 DESCRIPTION A C is considered a bad practice by a number of people, as it can lead to hard-to-understand and brittle spaghetti code. Instead of a C, use different control structures, or place a label on a block (such as a loop's block) and use C, C, or C instead. C is very different from C and is not covered by this policy. C is ambiguous and this policy will report such cases when C does not begin with C<&>. Whether this is a false positive or not cannot be determined by a static parse. =cut my $DESC = q{goto LABEL used}; my $EXPL = q{Considered bad practice}; sub violates { my ($self, $elem) = @_; return if $elem->content() ne 'goto'; my $target = $elem->snext_sibling(); return $self->violation('Nothing following "goto"?', 'It seems there is a lone "goto" in your code?', $elem) if !$target; return if $target->isa('PPI::Token::Symbol') && $target->raw_type eq '&' || $target->isa('PPI::Token::Cast') && $target->content eq '&' || $target->isa('PPI::Token::Word') && $target->content eq '__SUB__'; return $self->violation($DESC,$EXPL,$elem); } 1;