1Perl::Critic::Policy::SUPuseberrrlo:uC:toCinrntiertsii:bc:u:Rt:eePqdouliPireceryFl:i:nDSaoulcbRuremoteuuntrtinan(te3is)o:n:RequireFinalReturn(3)
2
3
4

NAME

6       Perl::Critic::Policy::Subroutines::RequireFinalReturn
7

DESCRIPTION

9       Require all subroutines to terminate explicitly with one of the follow‐
10       ing: "return", "goto", "die", "exit", "throw", "carp" or "croak".
11
12       Subroutines without explicit return statements at their ends can be
13       confusing.  It can be challenging to deduce what the return value will
14       be.
15
16       Furthermore, if the programmer did not mean for there to be a signifi‐
17       cant return value, and omits a return statement, some of the subrou‐
18       tine's inner data can leak to the outside.  Consider this case:
19
20          package Password;
21          # every time the user guesses the password wrong, it's value
22          # is rotated by one character
23          my $password;
24          sub set_password {
25             $password = shift;
26          }
27          sub check_password {
28             my $guess = shift;
29             if ($guess eq $password) {
30                unlock_secrets();
31             } else {
32                $password = (substr $password, 1).(substr $password, 0, 1);
33             }
34          }
35          1;
36
37       In this case, the last statement in check_password() is the assignment.
38       The result of that assignment is the implicit return value, so a wrong
39       guess returns the right password!  Adding a "return;" at the end of
40       that subroutine solves the problem.
41
42       The only exception allowed is an empty subroutine.
43

CONFIGURATION

45       If you've created your own terminal functions that behave like "die" or
46       "exit", then you can configure Perl::Critic to recognize those func‐
47       tions as well.  Just put something like this in your .perlcriticrc:
48
49         [Subroutines::RequireFinalReturns]
50         terminal_funcs = quit abort bailout
51

LIMITATIONS

53       We do not look for returns inside ternary operators.  That construction
54       is too complicated to analyze right now.  Besides, a better form is the
55       return outside of the ternary like this: "return foo ? 1 : bar ? 2 : 3"
56

AUTHOR

58       Chris Dolan <cdolan@cpan.org>
59
61       Copyright (c) 2005-2007 Chris Dolan.  All rights reserved.
62
63       This program is free software; you can redistribute it and/or modify it
64       under the same terms as Perl itself.  The full text of this license can
65       be found in the LICENSE file included with this module.
66
67
68
69perl v5.8.8           Perl::Critic2:0:0P7o-l0i3c-y2:0:Subroutines::RequireFinalReturn(3)
Impressum