Perl::...leCode(3pm)
π Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode π
okay bestie, welcome to the Perl::...leCode(3pm) page from the User Contributed Perl Documentation β yes, that manual name is giving truncated era, but the full policy is right here. It's the one that says don't write code after an unconditional "die, exit, or next" moment. π
πΈ 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. No extra side quest, it's already in the group chat. π«Ά
β¨ DESCRIPTION β¨
This policy literally prohibits code that comes after a statement which unconditionally alters the program flow. The crew includes calls to exit, die, return, next, last and goto. And because common usage said so, croak and confess from Carp are also included. π
A chunk of code counts as reachable if any of these conditions are true:
- Flow-altering statement has a conditional attached to it.
- Statement is on the right side of an operator
&&,||,//,and,or, orerr. - Code is prefixed with a label (can potentially be reached via
goto). - Code is a subroutine.
no cap: if the flow already dipped out unconditionally, anything after it is unreachable unless one of those conditions gives it a way back. β¨
π EXAMPLES π
here's the full example reel, bestie β same code, same comments, no edits. π
# not ok
exit;
print "123\n";
# ok
exit if !$xyz;
print "123\n";
# not ok
for ( 1 .. 10 ) {
next;
print 1;
}
# ok
for ( 1 .. 10 ) {
next if $_ == 5;
print 1;
}
# not ok
sub foo {
my $bar = shift;
return;
print 1;
}
# ok
sub foo {
my $bar = shift;
return if $bar->baz();
print 1;
}
# not ok
die;
print "123\n";
# ok
die;
LABEL: print "123\n";
# not ok
croak;
do_something();
# ok
croak;
sub do_something {}
π§ CONFIGURATION π§
This Policy is not configurable except for the standard options. That's the whole story, no hidden settings, no secret menu. π
π₯ SEE ALSO π₯
Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls
π AUTHOR π
Peter Guzis <pguzis@cpan.org>
π 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.
okay that's the page, bestie π source/version check: perl v5.42.0, dated 2024-10-23 β and the manual name up top is Perl::...leCode(3pm). byeee π«Ά
π¦ where this page comes from
- opensuse-leap 16.0: perl-Perl-Critic 1.156.0-bp160.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms