line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use utf8; |
3
|
8
|
|
|
8
|
|
5341
|
|
|
8
|
|
|
|
|
63
|
|
|
8
|
|
|
|
|
39
|
|
4
|
|
|
|
|
|
|
use 5.010; |
5
|
8
|
|
|
8
|
|
297
|
|
|
8
|
|
|
|
|
25
|
|
6
|
|
|
|
|
|
|
use strict; |
7
|
8
|
|
|
8
|
|
47
|
use warnings; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
227
|
|
8
|
8
|
|
|
8
|
|
44
|
|
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
391
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Readonly; |
12
|
8
|
|
|
8
|
|
54
|
|
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
418
|
|
13
|
|
|
|
|
|
|
use Perl::Critic::Utils qw{ :severities :data_conversion :classification }; |
14
|
8
|
|
|
8
|
|
45
|
|
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
416
|
|
15
|
|
|
|
|
|
|
use base 'Perl::Critic::Policy'; |
16
|
8
|
|
|
8
|
|
2756
|
|
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
2581
|
|
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
|
165809
|
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
|
88597
|
}, |
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
|
159
|
} |
50
|
|
|
|
|
|
|
|
51
|
8
|
|
|
|
|
24
|
my $statement_count = @{ $s }; |
52
|
|
|
|
|
|
|
if ( $statement_count <= $self->{ '_statement_count_limit' } ) { |
53
|
8
|
100
|
|
|
|
16939
|
return; |
54
|
1
|
|
|
|
|
4
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $desc; |
57
|
7
|
|
|
|
|
14
|
if ( my $name = $elem->name() ) { |
|
7
|
|
|
|
|
16
|
|
58
|
7
|
100
|
|
|
|
21
|
$desc = qq<Subroutine "$name" with high statement count ($statement_count)>; |
59
|
5
|
|
|
|
|
21
|
} |
60
|
|
|
|
|
|
|
else { |
61
|
|
|
|
|
|
|
# never the case becaus no PPI::Statement::Sub |
62
|
2
|
|
|
|
|
4
|
$desc = qq<Anonymous subroutine with high statement count ($statement_count)>; |
63
|
2
|
50
|
|
|
|
20
|
} |
64
|
2
|
|
|
|
|
128
|
|
65
|
|
|
|
|
|
|
return $self->violation( $desc, $EXPL, $elem ); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
0
|
1; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
2
|
|
|
|
|
13
|
#----------------------------------------------------------------------------- |
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<Mardem::RefactoringPerlCriticPolicies>. |
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 |