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