NAME
Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode - Don't write code after an unconditional "die, exit, or next".
AFFILIATION
This Policy is part of the core Perl::Critic distribution.
DESCRIPTION
This policy prohibits code following a statement which unconditionally alters the program flow. This includes calls to "exit", "die", "return", "next", "last" and "goto". Due to common usage, "croak" and "confess" from Carp are also included.
Code is reachable if any of the following conditions are true:
- •
-
Flow-altering statement has a conditional attached to it
- •
-
Statement is on the right side of an operator
"&&","||","//","and","or", or"err".
- •
-
Code is prefixed with a label (can potentially be reached via
"goto")
- •
-
Code is a subroutine
EXAMPLES
# not okexit;print "123\n";# okexit if !$xyz;print "123\n";# not okfor ( 1 .. 10 ) {next;print 1;}# okfor ( 1 .. 10 ) {next if $_ == 5;print 1;}# not oksub foo {my $bar = shift;return;print 1;}# oksub foo {my $bar = shift;return if $bar->baz();print 1;}# not okdie;print "123\n";# okdie;LABEL: print "123\n";# not okcroak;do_something();# okcroak;sub do_something {}
CONFIGURATION
This Policy is not configurable except for the standard options.
SEE ALSO
Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls
AUTHOR
Peter Guzis <[email protected]>
COPYRIGHT
Copyright (c) 2006-2011 Peter Guzis. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module.