line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use utf8; |
3
|
8
|
|
|
8
|
|
5454
|
|
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
41
|
|
4
|
|
|
|
|
|
|
use 5.010; |
5
|
8
|
|
|
8
|
|
293
|
|
|
8
|
|
|
|
|
26
|
|
6
|
|
|
|
|
|
|
use strict; |
7
|
8
|
|
|
8
|
|
32
|
use warnings; |
|
8
|
|
|
|
|
20
|
|
|
8
|
|
|
|
|
146
|
|
8
|
8
|
|
|
8
|
|
33
|
|
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
425
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Readonly; |
12
|
8
|
|
|
8
|
|
46
|
|
|
8
|
|
|
|
|
22
|
|
|
8
|
|
|
|
|
400
|
|
13
|
|
|
|
|
|
|
use Perl::Critic::Utils qw{ :severities :data_conversion :classification }; |
14
|
8
|
|
|
8
|
|
56
|
use Perl::Critic::Utils::McCabe qw{ calculate_mccabe_of_main }; |
|
8
|
|
|
|
|
19
|
|
|
8
|
|
|
|
|
414
|
|
15
|
8
|
|
|
8
|
|
2884
|
|
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
336
|
|
16
|
|
|
|
|
|
|
use Perl::Critic::Mardem::Util qw( search_for_block_keyword ); |
17
|
8
|
|
|
8
|
|
44
|
|
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
344
|
|
18
|
|
|
|
|
|
|
use base 'Perl::Critic::Policy'; |
19
|
8
|
|
|
8
|
|
45
|
|
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
2654
|
|
20
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => q{Consider refactoring}; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
{ |
23
|
|
|
|
|
|
|
return $SEVERITY_MEDIUM; |
24
|
|
|
|
|
|
|
} |
25
|
18
|
|
|
18
|
1
|
363
|
|
26
|
|
|
|
|
|
|
{ |
27
|
|
|
|
|
|
|
return qw(complexity maintenance); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
0
|
1
|
0
|
{ |
31
|
|
|
|
|
|
|
return 'PPI::Structure::Block'; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
{ |
35
|
23
|
|
|
23
|
1
|
304854
|
return ( |
36
|
|
|
|
|
|
|
{ 'name' => 'max_mccabe', |
37
|
|
|
|
|
|
|
'description' => 'The maximum complexity score allowed.', |
38
|
|
|
|
|
|
|
'default_string' => '10', |
39
|
|
|
|
|
|
|
'behavior' => 'integer', |
40
|
|
|
|
|
|
|
'integer_minimum' => 1, |
41
|
23
|
|
|
23
|
0
|
153110
|
}, |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
{ |
46
|
|
|
|
|
|
|
my ( $self, $elem, undef ) = @_; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $score = calculate_mccabe_of_main( $elem ); |
49
|
|
|
|
|
|
|
if ( $score <= $self->{ '_max_mccabe' } ) { |
50
|
|
|
|
|
|
|
return; |
51
|
|
|
|
|
|
|
} |
52
|
24
|
|
|
24
|
1
|
1307
|
|
53
|
|
|
|
|
|
|
my $block_keyword = search_for_block_keyword( $elem ); |
54
|
24
|
|
|
|
|
176
|
if ( !$block_keyword ) { |
55
|
24
|
100
|
|
|
|
17173
|
$block_keyword = 'no-keyword-found'; |
56
|
5
|
|
|
|
|
17
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
if ( 'SUB' eq $block_keyword ) { |
59
|
19
|
|
|
|
|
128
|
return; # no sub -> see SUB Perl::Critic::Policy::Subroutines::ProhibitExcessComplexity ! |
60
|
19
|
50
|
|
|
|
76
|
} |
61
|
0
|
|
|
|
|
0
|
|
62
|
|
|
|
|
|
|
my $desc = qq<"$block_keyword" code-block has a high complexity score ($score)>; |
63
|
|
|
|
|
|
|
return $self->violation( $desc, $EXPL, $elem ); |
64
|
19
|
100
|
|
|
|
80
|
} |
65
|
1
|
|
|
|
|
4
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
|
68
|
18
|
|
|
|
|
82
|
|
69
|
18
|
|
|
|
|
83
|
#----------------------------------------------------------------------------- |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=pod |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=encoding utf8 |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 NAME |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Perl::Critic::Policy::Mardem::ProhibitBlockComplexity |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 DESCRIPTION |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
This Policy approximates the McCabe score within a code block "eg if() {...}". |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
See L<http://en.wikipedia.org/wiki/Cyclomatic_complexity> |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
It should help to find complex code block, which should be extracted |
86
|
|
|
|
|
|
|
into subs, to be more testable. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
eg. from |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
if( $a ) { |
91
|
|
|
|
|
|
|
... |
92
|
|
|
|
|
|
|
... |
93
|
|
|
|
|
|
|
... |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
to |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
if( $a ) { |
99
|
|
|
|
|
|
|
do_something(); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 CONFIGURATION |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
The maximum acceptable McCabe can be set with the C<max_mccabe> |
105
|
|
|
|
|
|
|
configuration item. Any block with a McCabe score higher than |
106
|
|
|
|
|
|
|
this number will generate a policy violation. The default is 10. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
An example section for a F<.perlcriticrc>: |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
[Mardem::ProhibitBlockComplexity] |
111
|
|
|
|
|
|
|
max_mccabe = 1 |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 AFFILIATION |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
This policy is part of L<Perl::Critic::Mardem>. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 AUTHOR |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Markus Demml, mardem@cpan.com |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Copyright (c) 2022, Markus Demml |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it |
126
|
|
|
|
|
|
|
under the same terms as the Perl 5 programming language system itself. |
127
|
|
|
|
|
|
|
The full text of this license can be found in the LICENSE file included |
128
|
|
|
|
|
|
|
with this module. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |