1 ##############################################################################
2 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/t/Subroutines/RequireFinalReturn.run $
3 # $Date: 2008-03-16 17:40:45 -0500 (Sun, 16 Mar 2008) $
6 ##############################################################################
9 #-----------------------------------------------------------------------------
17 sub quux { return {some => [qw(complicated data)], q{ } => /structure/}; }
19 #-----------------------------------------------------------------------------
21 ## name complex passes
24 sub foo { if ($bool) { return; } else { return; } }
25 sub bar { unless ($bool) { return; } else { return; } }
26 sub baz { if ($bool) { return; } elsif ($bool2) { return; } else { return; } }
27 sub quuz { unless ($bool) { return; } elsif ($bool2) { return; } else { return; } }
29 #-----------------------------------------------------------------------------
31 ## name ternary returns
33 ## TODO We are not yet detecting ternaries
35 sub foo { 1 ? return : 2 ? return : return; }
37 #-----------------------------------------------------------------------------
39 ## name returning ternaries
42 sub foo { return 1 ? 1 : 2 ? 2 : 3; }
44 #-----------------------------------------------------------------------------
46 ## name implicit returns fail
50 sub foo { 'Club sandwich'; }
52 #-----------------------------------------------------------------------------
54 ## name return in a constant loop
57 sub foo { while (1==1) { return; } }
59 #-----------------------------------------------------------------------------
61 ## name not all code paths returns
64 sub foo { if ($bool) { } else { } }
65 sub foo { if ($bool) { $foo = 'bar'; } else { return; } }
66 sub foo { unless ($bool) { $foo = 'bar'; } else { return; } }
68 #-----------------------------------------------------------------------------
70 ## name special blocks exemption
74 print 'this should not need a return';
86 #-----------------------------------------------------------------------------
88 ## name goto is equivalent to return
91 sub foo { goto &bar; }
94 #-----------------------------------------------------------------------------
96 ## name next and last are not equivalent to return (and are invalid Perl)
102 #-----------------------------------------------------------------------------
104 ## name abnormal termination is allowed
110 sub bar_C { Carp::croak; }
111 sub baz_C { Carp::confess; }
113 sub quux2 { throw 'nuts'; }
115 #-----------------------------------------------------------------------------
117 ## name Final return is present, but conditional
120 sub foo { die if $condition }
121 sub bar { croak unless $condition }
122 sub baz { exit for @condition }
123 sub quux { throw 'nuts'if not $condition }
125 #-----------------------------------------------------------------------------
127 ## name Compound final return is present, but conditional
133 return if $today_is_tuesday;
136 exit unless $today_is_wednesday;
140 #-----------------------------------------------------------------------------
142 ## name Custom terminals
143 ## parms { terminal_funcs => 'bailout abort quit' };
146 sub foo { if ($condition) { return 1; }else{ abort } }
147 sub bar { if ($condition) { bailout }else{ return 1 } }
150 ##############################################################################
153 # cperl-indent-level: 4
155 # indent-tabs-mode: nil
156 # c-indentation-style: bsd
158 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :