Perl::...Return(3pm)
π Perl::Critic::Policy::Community::ConditionalImplicitReturn π
okay bestie, so this is a page from the User Contributed Perl Documentation, section 3pm, and the whole thing is about one specific lil Perl::Critic policy. it's giving "your sub is lying to you about what it returns" energy and honestly? we need to talk about it.
β¨ NAME β¨
Perl::Critic::Policy::Community::ConditionalImplicitReturn β don't end a subroutine with a conditional block</p> π
like, don't do it. that's the whole policy. periodt.
πΈ DESCRIPTION πΈ
so picture this: the last statement in your subroutine is a conditional block, like if ($foo) { ... }, and you never handled the else. bestie. π what happens when that condition is false? the sub just... returns something unexpected, and that is almost definitely a logic error, not a vibe. so either specify a return value after the conditional, or handle the else condition. no in-between, no "it'll probably be fine".
here's the visual, keep it in your notes:
sub { ... if ($foo) { return 1 } } # not ok
sub { ... if ($foo) { return 1 } return 0 } # ok
sub { ... if ($foo) { return 1 } else { return 0 } } # ok
see how the first one is just out here with no plan? not ok. the other two? iconic, correct, hydrated. β¨
lowkey important detail: this policy only kicks in if the subroutine contains a return statement with an explicit return value. that's the lil signal that tells us the sub was not intended to be used in void context. no explicit return value anywhere? then we mind our business. π«Ά
π¦ CAVEATS π¦
okay so, being real with you, this policy currently only checks for implicitly returned conditionals in named subroutines. anonymous subroutines? not checked. not today, maybe not ever, who's to say. π
and also β return statements that live inside blocks, other than compound statements like if and foreach, are not considered when we're figuring out whether a function is intended to be used in void context. so if you're being clever with bare blocks, the policy is not reading your mind. π
π AFFILIATION π
this policy is part of Perl::Critic::Community. it has a home, it has a family, it belongs. π₯Ή
π CONFIGURATION π
not configurable bestie!! this policy is not configurable except for the standard options. that's it, that's the whole section, no knobs to turn, no secret menu. π ββοΈ
π AUTHOR π
Dan Book, dbook@cpan.org β thank you for your service, king. π«‘
π 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.
(that's the legal bit, and yes it still counts even when it's written with butterflies around it. π¦)
β SEE ALSO β
Perl::Criticβ the main character, go read it, iykyk π
and that's the whole page, bestie!! no cap, every option, caveat and copyright line made it in. this one came from perl v5.40.1, dated 2025-03-22, and it lives in the User Contributed Perl Documentation corner of the manual β mwah, slay, go write a return statement after your conditional. π
β¨π
π¦ where this page comes from
- debian trixie: libperl-critic-community-perl 1.0.4-1 Β· Artistic-2.0
- ubuntu resolute: libperl-critic-community-perl 1.0.4-1 Β· Artistic-2.0
- ubuntu stonking: libperl-critic-community-perl 1.0.4-1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms