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, or err.
  • 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 (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