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