The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Perl::Critic::Policy::Freenode::ConditionalImplicitReturn - Don't end a subroutine with a conditional block

DESCRIPTION

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 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.

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::Freenode.

CONFIGURATION

This policy is not configurable except for the standard options.

AUTHOR

Dan Book, dbook@cpan.org

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.

SEE ALSO

Perl::Critic