1Perl::Critic::Policy::SUPuseberrrlo:uC:toCinrntiertsii:bc:u:Pt:rePodohliPibecirytl:R:eDStouucbrurnmoSeuontrtitan(te3is)o:n:ProhibitReturnSort(3)
2
3
4
6 Perl::Critic::Policy::Subroutines::ProhibitReturnSort - Behavior of
7 "sort" is not defined if called in scalar context.
8
10 This Policy is part of the core Perl::Critic distribution.
11
13 The behavior of the builtin "sort" function is not defined if called in
14 scalar context. So if you write a subroutine that directly "return"s
15 the result of a "sort" operation, then you code will behave
16 unpredictably if someone calls your subroutine in a scalar context.
17 This Policy emits a violation if the "return" keyword is directly
18 followed by the "sort" function. To safely return a sorted list of
19 values from a subroutine, you should assign the sorted values to a
20 temporary variable first. For example:
21
22 sub frobulate {
23
24 return sort @list; # not ok!
25
26 my @sorted_list = sort @list;
27 return @sorted_list # OK
28 }
29
31 This Policy is not sensitive to the "wantarray" function. So the
32 following code would generate a false violation:
33
34 sub frobulate {
35
36 if (wantarray) {
37 return sort @list;
38 }
39 else{
40 return join @list;
41 }
42 }
43
45 This Policy is not configurable except for the standard options.
46
48 This Policy was suggested by Ulrich Wisser and the <http://iis.se>
49 team.
50
52 Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>
53
55 Copyright (c) 2005-2017 Imaginative Software Systems. All rights
56 reserved.
57
58 This program is free software; you can redistribute it and/or modify it
59 under the same terms as Perl itself. The full text of this license can
60 be found in the LICENSE file included with this module.
61
62
63
64perl v5.28.0 Perl::Critic2:0:1P8o-l0i7c-y1:5:Subroutines::ProhibitReturnSort(3)