line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Critic::Policy::ControlStructures::ProhibitUnlessBlocks; |
2
|
|
|
|
|
|
|
|
3
|
40
|
|
|
40
|
|
26968
|
use 5.010001; |
|
40
|
|
|
|
|
173
|
|
4
|
40
|
|
|
40
|
|
263
|
use strict; |
|
40
|
|
|
|
|
107
|
|
|
40
|
|
|
|
|
819
|
|
5
|
40
|
|
|
40
|
|
244
|
use warnings; |
|
40
|
|
|
|
|
117
|
|
|
40
|
|
|
|
|
1115
|
|
6
|
40
|
|
|
40
|
|
241
|
use Readonly; |
|
40
|
|
|
|
|
104
|
|
|
40
|
|
|
|
|
2278
|
|
7
|
|
|
|
|
|
|
|
8
|
40
|
|
|
40
|
|
332
|
use Perl::Critic::Utils qw{ :severities }; |
|
40
|
|
|
|
|
139
|
|
|
40
|
|
|
|
|
2023
|
|
9
|
40
|
|
|
40
|
|
5256
|
use parent 'Perl::Critic::Policy'; |
|
40
|
|
|
|
|
122
|
|
|
40
|
|
|
|
|
244
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '1.148'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Readonly::Scalar my $DESC => q{"unless" block used}; |
16
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => [ 97 ]; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
19
|
|
|
|
|
|
|
|
20
|
91
|
|
|
91
|
0
|
1777
|
sub supported_parameters { return () } |
21
|
77
|
|
|
77
|
1
|
366
|
sub default_severity { return $SEVERITY_LOW } |
22
|
84
|
|
|
84
|
1
|
321
|
sub default_themes { return qw(core pbp cosmetic) } |
23
|
32
|
|
|
32
|
1
|
119
|
sub applies_to { return 'PPI::Statement::Compound' } |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub violates { |
28
|
13
|
|
|
13
|
1
|
51
|
my ( $self, $elem, undef ) = @_; |
29
|
|
|
|
|
|
|
|
30
|
13
|
100
|
|
|
|
66
|
if ( $elem->first_element() eq 'unless' ) { |
31
|
3
|
|
|
|
|
73
|
return $self->violation( $DESC, $EXPL, $elem ); |
32
|
|
|
|
|
|
|
} |
33
|
10
|
|
|
|
|
296
|
return; #ok! |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
1; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
__END__ |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=pod |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 NAME |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Perl::Critic::Policy::ControlStructures::ProhibitUnlessBlocks - Write C<if(! $condition)> instead of C<unless($condition)>. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 AFFILIATION |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
This Policy is part of the core L<Perl::Critic|Perl::Critic> |
51
|
|
|
|
|
|
|
distribution. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 DESCRIPTION |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Conway discourages using C<unless> because it leads to |
57
|
|
|
|
|
|
|
double-negatives that are hard to understand. Instead, reverse the |
58
|
|
|
|
|
|
|
logic and use C<if>. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
unless($condition) { do_something() } #not ok |
61
|
|
|
|
|
|
|
unless(! $no_flag) { do_something() } #really bad |
62
|
|
|
|
|
|
|
if( ! $condition) { do_something() } #ok |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
This Policy only covers the block-form of C<unless>. For the postfix |
65
|
|
|
|
|
|
|
variety, see C<ProhibitPostfixControls>. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 CONFIGURATION |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
This Policy is not configurable except for the standard options. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 SEE ALSO |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
L<Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls|Perl::Critic::Policy::ControlStructures::ProhibitPostfixControls> |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 AUTHOR |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Jeffrey Ryan Thalhammer <jeff@imaginative-software.com> |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 COPYRIGHT |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Copyright (c) 2005-2011 Imaginative Software Systems. All rights reserved. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
86
|
|
|
|
|
|
|
it under the same terms as Perl itself. The full text of this license |
87
|
|
|
|
|
|
|
can be found in the LICENSE file included with this module. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# Local Variables: |
92
|
|
|
|
|
|
|
# mode: cperl |
93
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
94
|
|
|
|
|
|
|
# fill-column: 78 |
95
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
96
|
|
|
|
|
|
|
# c-indentation-style: bsd |
97
|
|
|
|
|
|
|
# End: |
98
|
|
|
|
|
|
|
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |