line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use utf8; |
3
|
8
|
|
|
8
|
|
5159
|
|
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
43
|
|
4
|
|
|
|
|
|
|
use 5.010; |
5
|
8
|
|
|
8
|
|
279
|
|
|
8
|
|
|
|
|
27
|
|
6
|
|
|
|
|
|
|
use strict; |
7
|
8
|
|
|
8
|
|
37
|
use warnings; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
201
|
|
8
|
8
|
|
|
8
|
|
37
|
|
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
361
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Readonly; |
12
|
8
|
|
|
8
|
|
51
|
|
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
432
|
|
13
|
|
|
|
|
|
|
use Perl::Critic::Utils qw{ :severities :data_conversion :classification }; |
14
|
8
|
|
|
8
|
|
47
|
|
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
396
|
|
15
|
|
|
|
|
|
|
use Perl::Critic::Mardem::Util qw( search_for_block_keyword ); |
16
|
8
|
|
|
8
|
|
2745
|
|
|
8
|
|
|
|
|
24
|
|
|
8
|
|
|
|
|
322
|
|
17
|
|
|
|
|
|
|
use base 'Perl::Critic::Policy'; |
18
|
8
|
|
|
8
|
|
42
|
|
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
2781
|
|
19
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => q{Consider refactoring}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
{ |
22
|
|
|
|
|
|
|
return $SEVERITY_MEDIUM; |
23
|
|
|
|
|
|
|
} |
24
|
18
|
|
|
18
|
1
|
225
|
|
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
|
264575
|
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
|
124117
|
}, |
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
|
945
|
} |
52
|
|
|
|
|
|
|
|
53
|
27
|
|
|
|
|
88
|
my $statement_count = @{ $s }; |
54
|
|
|
|
|
|
|
if ( $statement_count <= $self->{ '_statement_count_limit' } ) { |
55
|
27
|
100
|
|
|
|
19219
|
return; |
56
|
1
|
|
|
|
|
5
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $block_keyword = search_for_block_keyword( $elem ); |
59
|
26
|
|
|
|
|
57
|
if ( !$block_keyword ) { |
|
26
|
|
|
|
|
57
|
|
60
|
26
|
100
|
|
|
|
82
|
$block_keyword = 'no-keyword-found'; |
61
|
6
|
|
|
|
|
59
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
if ( 'SUB' eq $block_keyword ) { |
64
|
20
|
|
|
|
|
102
|
return; # no sub -> see SUB Perl::Critic::Policy::Mardem::ProhibitLargeSub ! |
65
|
20
|
50
|
|
|
|
51
|
} |
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
|
|
|
|
50
|
} |
70
|
2
|
|
|
|
|
13
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
|
73
|
18
|
|
|
|
|
46
|
|
74
|
18
|
|
|
|
|
68
|
#----------------------------------------------------------------------------- |
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<Perl::Critic::Mardem>. |
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 |