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