Perl::Critic::Policy::Freenode::ConditionalImplicitReturn - Don't end a subroutine with a conditional block
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.
if ($foo) { ... }
else
sub { ... if ($foo) { return 1 } } # not ok sub { ... if ($foo) { return 1 } return 0 } # ok sub { ... 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.
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.
if
foreach
This policy is part of Perl::Critic::Freenode.
This policy is not configurable except for the standard options.
Dan Book, dbook@cpan.org
dbook@cpan.org
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.
Perl::Critic
To install Perl::Critic::Freenode, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Perl::Critic::Freenode
CPAN shell
perl -MCPAN -e shell install Perl::Critic::Freenode
For more information on module installation, please visit the detailed CPAN module installation guide.