line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use utf8; |
3
|
8
|
|
|
8
|
|
4904
|
|
|
8
|
|
|
|
|
19
|
|
|
8
|
|
|
|
|
35
|
|
4
|
|
|
|
|
|
|
use 5.010; |
5
|
8
|
|
|
8
|
|
266
|
|
|
8
|
|
|
|
|
51
|
|
6
|
|
|
|
|
|
|
use strict; |
7
|
8
|
|
|
8
|
|
34
|
use warnings; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
145
|
|
8
|
8
|
|
|
8
|
|
34
|
|
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
390
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Readonly; |
12
|
8
|
|
|
8
|
|
59
|
|
|
8
|
|
|
|
|
21
|
|
|
8
|
|
|
|
|
395
|
|
13
|
|
|
|
|
|
|
use Perl::Critic::Utils qw{ :severities :data_conversion :classification }; |
14
|
8
|
|
|
8
|
|
49
|
use Perl::Critic::Utils::McCabe qw{ calculate_mccabe_of_main }; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
347
|
|
15
|
8
|
|
|
8
|
|
2586
|
|
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
350
|
|
16
|
|
|
|
|
|
|
use Perl::Critic::Mardem::Util qw( search_for_block_keyword ); |
17
|
8
|
|
|
8
|
|
42
|
|
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
331
|
|
18
|
|
|
|
|
|
|
use base 'Perl::Critic::Policy'; |
19
|
8
|
|
|
8
|
|
47
|
|
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
2478
|
|
20
|
|
|
|
|
|
|
Readonly::Scalar my $EXPL => q{Consider refactoring}; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
{ |
23
|
|
|
|
|
|
|
return $SEVERITY_MEDIUM; |
24
|
|
|
|
|
|
|
} |
25
|
18
|
|
|
18
|
1
|
175
|
|
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
|
257095
|
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
|
114394
|
}, |
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
|
851
|
|
53
|
|
|
|
|
|
|
my $block_keyword = search_for_block_keyword( $elem ); |
54
|
24
|
|
|
|
|
61
|
if ( !$block_keyword ) { |
55
|
24
|
100
|
|
|
|
14940
|
$block_keyword = 'no-keyword-found'; |
56
|
5
|
|
|
|
|
12
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
if ( 'SUB' eq $block_keyword ) { |
59
|
19
|
|
|
|
|
59
|
return; # no sub -> see SUB Perl::Critic::Policy::Subroutines::ProhibitExcessComplexity ! |
60
|
19
|
50
|
|
|
|
64
|
} |
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
|
|
|
|
39
|
} |
65
|
1
|
|
|
|
|
4
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
|
68
|
18
|
|
|
|
|
45
|
|
69
|
18
|
|
|
|
|
54
|
#----------------------------------------------------------------------------- |
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 |