Perl::Critic::Policy::Community::ConditionalImplicitReturn3pm
Don't end a subroutine with a conditional block
Overview
If the last statement in a subroutine is a conditional block such as "if ($foo) { ... }", and the "else" condition is not handled, the subroutine will return an unexpected value when the condition fails, and it is most likely a logic error. Specify a return value after the conditional, or handle the "else" condition.
sub { ... if ($foo) { return 1 } } # not oksub { ... if ($foo) { return 1 } return 0 } # oksub { ... if ($foo) { return 1 } else { return 0 } } # ok
This policy only applies if the subroutine contains a return statement with an explicit return value, indicating it is not intended to be used in void context.
Caveats
This policy currently only checks for implicitly returned conditionals in named subroutines, anonymous subroutines are not checked. Also, return statements within blocks, other than compound statements like "if" and "foreach", are not considered when determining if a function is intended to be used in void context.
Affiliation
This policy is part of Perl::Critic::Community.
Configuration
This policy is not configurable except for the standard options.
Copyright and license
Copyright 2015, Dan Book.
This library is free software; you may redistribute it and/or modify it under the terms of the Artistic License version 2.0.
Releases
2 releases since Debian 12 (Bookworm); the text changed 1 time.