line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use utf8; |
3
|
8
|
|
|
8
|
|
5300
|
|
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
48
|
|
4
|
|
|
|
|
|
|
use 5.010; |
5
|
8
|
|
|
8
|
|
287
|
|
|
8
|
|
|
|
|
25
|
|
6
|
|
|
|
|
|
|
use strict; |
7
|
8
|
|
|
8
|
|
38
|
use warnings; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
130
|
|
8
|
8
|
|
|
8
|
|
31
|
|
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
352
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Readonly; |
12
|
8
|
|
|
8
|
|
68
|
|
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
405
|
|
13
|
|
|
|
|
|
|
use Perl::Critic::Utils qw{ :severities :data_conversion :classification }; |
14
|
8
|
|
|
8
|
|
80
|
|
|
8
|
|
|
|
|
21
|
|
|
8
|
|
|
|
|
420
|
|
15
|
|
|
|
|
|
|
use base 'Perl::Critic::Policy'; |
16
|
8
|
|
|
8
|
|
2789
|
|
|
8
|
|
|
|
|
34
|
|
|
8
|
|
|
|
|
3057
|
|
17
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => q{Consider refactoring}; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
{ |
20
|
|
|
|
|
|
|
return $SEVERITY_MEDIUM; |
21
|
|
|
|
|
|
|
} |
22
|
8
|
|
|
8
|
1
|
82
|
|
23
|
|
|
|
|
|
|
{ |
24
|
|
|
|
|
|
|
return qw(complexity maintenance); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
0
|
1
|
0
|
{ |
28
|
|
|
|
|
|
|
return 'PPI::Statement::Sub'; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
{ |
32
|
13
|
|
|
13
|
1
|
188262
|
return ( |
33
|
|
|
|
|
|
|
{ 'name' => 'condition_count_limit', |
34
|
|
|
|
|
|
|
'description' => 'The maximum condition count allowed.', |
35
|
|
|
|
|
|
|
'default_string' => '3', |
36
|
|
|
|
|
|
|
'behavior' => 'integer', |
37
|
|
|
|
|
|
|
'integer_minimum' => 1, |
38
|
13
|
|
|
13
|
0
|
93048
|
}, |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
{ |
43
|
|
|
|
|
|
|
my ( $self, $elem, undef ) = @_; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $s = $elem->find( |
46
|
|
|
|
|
|
|
sub |
47
|
|
|
|
|
|
|
{ |
48
|
|
|
|
|
|
|
my ( undef, $element ) = @_; |
49
|
11
|
|
|
11
|
1
|
204
|
|
50
|
|
|
|
|
|
|
my $interesting = |
51
|
|
|
|
|
|
|
$element->isa( 'PPI::Structure::Condition' ) |
52
|
|
|
|
|
|
|
|| $element->isa( 'PPI::Structure::For' ) |
53
|
|
|
|
|
|
|
|| $element->isa( 'PPI::Structure::Given' ); |
54
|
783
|
|
|
783
|
|
6375
|
|
55
|
|
|
|
|
|
|
return $interesting; |
56
|
783
|
|
100
|
|
|
3647
|
} |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
if ( !$s ) { |
60
|
|
|
|
|
|
|
return; |
61
|
783
|
|
|
|
|
1448
|
} |
62
|
|
|
|
|
|
|
|
63
|
11
|
|
|
|
|
52
|
my $condition_count = @{ $s }; |
64
|
|
|
|
|
|
|
if ( $condition_count <= $self->{ '_condition_count_limit' } ) { |
65
|
11
|
100
|
|
|
|
134
|
return; |
66
|
1
|
|
|
|
|
4
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $desc; |
69
|
10
|
|
|
|
|
12
|
if ( my $name = $elem->name() ) { |
|
10
|
|
|
|
|
19
|
|
70
|
10
|
100
|
|
|
|
36
|
$desc = qq<Subroutine "$name" with high condition count ($condition_count)>; |
71
|
2
|
|
|
|
|
6
|
} |
72
|
|
|
|
|
|
|
else { |
73
|
|
|
|
|
|
|
# never the case becaus no PPI::Statement::Sub |
74
|
8
|
|
|
|
|
11
|
$desc = qq<Anonymous subroutine with high condition count ($condition_count)>; |
75
|
8
|
50
|
|
|
|
30
|
} |
76
|
8
|
|
|
|
|
417
|
|
77
|
|
|
|
|
|
|
return $self->violation( $desc, $EXPL, $elem ); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
0
|
1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
8
|
|
|
|
|
29
|
#----------------------------------------------------------------------------- |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=pod |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=encoding utf8 |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 NAME |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Perl::Critic::Policy::Mardem::ProhibitManyConditionsInSub |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 DESCRIPTION |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
This Policy counts the conditions within a sub. |
96
|
|
|
|
|
|
|
(more precise the PPI::Structure::Condition's, |
97
|
|
|
|
|
|
|
PPI::Structure::For's and PPI::Structure::Given's) |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 CONFIGURATION |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
The maximum acceptable Condition-Count can be set with the |
102
|
|
|
|
|
|
|
C<condition_count_limit> configuration item. Any sub with a count higher than |
103
|
|
|
|
|
|
|
this number will generate a policy violation. The default is 3. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
An example section for a F<.perlcriticrc>: |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
[Mardem::ProhibitManyConditionsInSub] |
108
|
|
|
|
|
|
|
condition_count_limit = 1 |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 AFFILIATION |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
This policy is part of L<Perl::Critic::Mardem>. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 AUTHOR |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Markus Demml, mardem@cpan.com |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Copyright (c) 2022, Markus Demml |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it |
123
|
|
|
|
|
|
|
under the same terms as the Perl 5 programming language system itself. |
124
|
|
|
|
|
|
|
The full text of this license can be found in the LICENSE file included |
125
|
|
|
|
|
|
|
with this module. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |