line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use utf8; |
3
|
8
|
|
|
8
|
|
5194
|
|
|
8
|
|
|
|
|
70
|
|
|
8
|
|
|
|
|
40
|
|
4
|
|
|
|
|
|
|
use 5.010; |
5
|
8
|
|
|
8
|
|
287
|
|
|
8
|
|
|
|
|
27
|
|
6
|
|
|
|
|
|
|
use strict; |
7
|
8
|
|
|
8
|
|
34
|
use warnings; |
|
8
|
|
|
|
|
26
|
|
|
8
|
|
|
|
|
165
|
|
8
|
8
|
|
|
8
|
|
38
|
|
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
398
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Readonly; |
12
|
8
|
|
|
8
|
|
69
|
use Perl::Critic::Utils qw( is_hash_key $SEVERITY_MEDIUM ); |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
489
|
|
13
|
8
|
|
|
8
|
|
87
|
|
|
8
|
|
|
|
|
32
|
|
|
8
|
|
|
|
|
748
|
|
14
|
|
|
|
|
|
|
use base 'Perl::Critic::Policy'; |
15
|
8
|
|
|
8
|
|
62
|
|
|
8
|
|
|
|
|
19
|
|
|
8
|
|
|
|
|
2878
|
|
16
|
|
|
|
|
|
|
## no critic (RequireInterpolationOfMetachars) |
17
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => q{Consider using some $false, $true or other available module implementation}; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Readonly::Scalar my $DESC => q{"return" statement with explicit "0/1"}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
{ |
22
|
|
|
|
|
|
|
return $SEVERITY_MEDIUM; |
23
|
|
|
|
|
|
|
} |
24
|
11
|
|
|
11
|
1
|
100
|
|
25
|
|
|
|
|
|
|
{ |
26
|
|
|
|
|
|
|
return qw(complexity maintenance); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
0
|
1
|
0
|
{ |
30
|
|
|
|
|
|
|
return 'PPI::Statement::Break'; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
{ |
34
|
22
|
|
|
22
|
1
|
100063
|
return; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
{ |
38
|
|
|
|
|
|
|
my ( $self, $elem, undef ) = @_; |
39
|
22
|
|
|
22
|
0
|
71593
|
|
40
|
|
|
|
|
|
|
my $return_keyword = $elem->schild(); # not next element - need first child |
41
|
|
|
|
|
|
|
if ( !$return_keyword ) { |
42
|
|
|
|
|
|
|
return; |
43
|
|
|
|
|
|
|
} |
44
|
18
|
|
|
18
|
1
|
309
|
|
45
|
|
|
|
|
|
|
if ( 'return' ne $return_keyword->content() || is_hash_key( $return_keyword ) ) { |
46
|
18
|
|
|
|
|
48
|
return; |
47
|
18
|
50
|
|
|
|
248
|
} |
48
|
0
|
|
|
|
|
0
|
|
49
|
|
|
|
|
|
|
my $return_line_content = $elem->content(); |
50
|
|
|
|
|
|
|
if ( !$return_line_content ) { |
51
|
18
|
50
|
33
|
|
|
49
|
return; |
52
|
0
|
|
|
|
|
0
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# fast regex violation check - eg. "return 1"; - "return (1); # comment" - "return 1 if ..." |
55
|
18
|
|
|
|
|
1004
|
my $return = q{return}; |
56
|
18
|
50
|
|
|
|
559
|
my $value = q{[(]?\s*[01]\s*[)]?}; |
57
|
0
|
|
|
|
|
0
|
my $opt_condition = q{(?:(?:if|unless)\s*[(]?\s*.+\s*[)]?\s*)?}; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my $regex = qr/^\s*$return\s*$value\s*$opt_condition\s*;/ixmso; |
60
|
|
|
|
|
|
|
|
61
|
18
|
|
|
|
|
27
|
if ( $return_line_content !~ $regex ) { |
62
|
18
|
|
|
|
|
26
|
return; |
63
|
18
|
|
|
|
|
21
|
} |
64
|
|
|
|
|
|
|
|
65
|
18
|
|
|
|
|
100
|
return $self->violation( $DESC, $EXPL, $elem ); |
66
|
|
|
|
|
|
|
} |
67
|
18
|
100
|
|
|
|
184
|
|
68
|
7
|
|
|
|
|
28
|
1; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
11
|
|
|
|
|
40
|
#----------------------------------------------------------------------------- |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=pod |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=encoding utf8 |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 NAME |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Perl::Critic::Policy::Mardem::ProhibitReturnBooleanAsInt |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 DESCRIPTION |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
This Policy searches for C<return 1> and C<return 0> statements, |
84
|
|
|
|
|
|
|
which are mainly used for boolean meaning, but are less expressiv |
85
|
|
|
|
|
|
|
than direct use of some boolean eg. C<return $true>. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
There are many different modules available for true, false - use it! |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 CONFIGURATION |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
No Configuration |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 AFFILIATION |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
This policy is part of L<Perl::Critic::Mardem>. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 AUTHOR |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Markus Demml, mardem@cpan.com |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Copyright (c) 2022, Markus Demml |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it |
106
|
|
|
|
|
|
|
under the same terms as the Perl 5 programming language system itself. |
107
|
|
|
|
|
|
|
The full text of this license can be found in the LICENSE file included |
108
|
|
|
|
|
|
|
with this module. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |