line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Critic::Policy::ProhibitOrReturn; |
2
|
3
|
|
|
3
|
|
800880
|
use 5.008001; |
|
3
|
|
|
|
|
28
|
|
3
|
3
|
|
|
3
|
|
19
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
69
|
|
4
|
3
|
|
|
3
|
|
18
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
107
|
|
5
|
3
|
|
|
3
|
|
504
|
use parent 'Perl::Critic::Policy'; |
|
3
|
|
|
|
|
315
|
|
|
3
|
|
|
|
|
24
|
|
6
|
3
|
|
|
3
|
|
258906
|
use constant DESC => '`or return` in source file'; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
238
|
|
7
|
3
|
|
|
3
|
|
21
|
use constant EXPL => '`or return` is prohibited. Use equivalent conditional statement instead.'; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
147
|
|
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
19
|
use Perl::Critic::Utils qw( :severities ); |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
202
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = "0.02"; |
12
|
|
|
|
|
|
|
|
13
|
4
|
|
|
4
|
0
|
1125293
|
sub supported_parameters { return (); } |
14
|
3
|
|
|
3
|
1
|
59
|
sub default_severity { return $SEVERITY_MEDIUM; } |
15
|
0
|
|
|
0
|
1
|
0
|
sub default_themes { return qw(bugs complexity maintenance); } |
16
|
4
|
|
|
4
|
1
|
1034571
|
sub applies_to { return 'PPI::Token::Word'; } |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub violates { |
19
|
22
|
|
|
22
|
1
|
1050
|
my ($self, $elem, undef) = @_; |
20
|
|
|
|
|
|
|
|
21
|
22
|
100
|
|
|
|
58
|
return if $elem->content ne 'return'; |
22
|
|
|
|
|
|
|
|
23
|
9
|
|
|
|
|
79
|
my $sprev = $elem->sprevious_sibling; |
24
|
9
|
100
|
|
|
|
270
|
return if !$sprev; |
25
|
3
|
50
|
|
|
|
10
|
return if $sprev->content ne 'or'; |
26
|
|
|
|
|
|
|
|
27
|
3
|
|
|
|
|
29
|
return $self->violation(DESC, EXPL, $elem->parent); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
1; |
31
|
|
|
|
|
|
|
__END__ |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=encoding utf-8 |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 NAME |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Perl::Critic::Policy::ProhibitOrReturn - Do not use `or return` |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 AFFILIATION |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
This policy is a policy in the L<Perl::Critic::Policy::ProhibitOrReturn> distribution. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 DESCRIPTION |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Avoid using C<or return>. Consider using equivalent C<if> (or C<unless>) statement instead. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# not ok |
48
|
|
|
|
|
|
|
sub foo { |
49
|
|
|
|
|
|
|
my ($x) = @_; |
50
|
|
|
|
|
|
|
$x or return; |
51
|
|
|
|
|
|
|
... |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# ok |
55
|
|
|
|
|
|
|
sub foo { |
56
|
|
|
|
|
|
|
my ($x) = @_; |
57
|
|
|
|
|
|
|
return if !$x; |
58
|
|
|
|
|
|
|
... |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 CONFIGURATION |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
This Policy is not configurable except for the standard options. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 LICENSE |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Copyright (C) utgwkk. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
70
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 AUTHOR |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
utgwkk E<lt>utagawakiki@gmail.comE<gt> |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
|