line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Perl::Metrics::Lite; |
2
|
4
|
|
|
4
|
|
14353
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
179
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.2'; |
4
|
|
|
|
|
|
|
|
5
|
4
|
|
|
4
|
|
13403
|
use List::MoreUtils qw(any); |
|
4
|
|
|
|
|
5656
|
|
|
4
|
|
|
|
|
538
|
|
6
|
4
|
|
|
4
|
|
3816
|
use Perl::Metrics::Lite; |
|
4
|
|
|
|
|
994267
|
|
|
4
|
|
|
|
|
137
|
|
7
|
4
|
|
|
4
|
|
2356
|
use Test::More (); |
|
4
|
|
|
|
|
17
|
|
|
4
|
|
|
|
|
104
|
|
8
|
4
|
|
|
4
|
|
22
|
use Test::Builder; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
266
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my %METRICS_ARGS; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $TEST = Test::Builder->new; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub import { |
15
|
4
|
|
|
4
|
|
44
|
my ( $self, %args ) = @_; |
16
|
|
|
|
|
|
|
|
17
|
4
|
|
|
|
|
17
|
my $caller = caller; |
18
|
|
|
|
|
|
|
{ |
19
|
4
|
|
|
4
|
|
21
|
no strict 'refs'; ## no critic qw(ProhibitNoStrict) |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
3591
|
|
|
4
|
|
|
|
|
20
|
|
20
|
4
|
|
|
|
|
10
|
*{ $caller . '::all_metrics_ok' } = \&all_metrics_ok; |
|
4
|
|
|
|
|
29
|
|
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
4
|
|
|
|
|
27
|
$TEST->exported_to($caller); |
24
|
|
|
|
|
|
|
|
25
|
4
|
|
|
|
|
14
|
%METRICS_ARGS = %args; |
26
|
4
|
|
100
|
|
|
36
|
$METRICS_ARGS{-mccabe_complexity} ||= 10; |
27
|
4
|
|
100
|
|
|
26
|
$METRICS_ARGS{-loc} ||= 60; |
28
|
|
|
|
|
|
|
|
29
|
4
|
|
|
|
|
135
|
return 1; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub all_code_files { |
33
|
3
|
50
|
|
3
|
0
|
4
|
my @exceptions = @{ $METRICS_ARGS{-except_dir} || [] }; |
|
3
|
|
|
|
|
37
|
|
34
|
3
|
|
|
|
|
8
|
my @dirs = @_; |
35
|
3
|
50
|
|
|
|
10
|
if ( not @dirs ) { |
36
|
0
|
|
|
|
|
0
|
@dirs = _starting_points(); |
37
|
|
|
|
|
|
|
} |
38
|
3
|
|
|
|
|
7
|
@dirs = grep { !is_excluded( $_, @exceptions ) } @dirs; |
|
3
|
|
|
|
|
12
|
|
39
|
3
|
|
|
|
|
9
|
return \@dirs; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub is_excluded { |
43
|
8
|
|
|
8
|
0
|
19
|
my ( $path, @exceptions ) = @_; |
44
|
8
|
100
|
|
2
|
|
106
|
any { $path eq $_ || $path =~ /$_/ } @exceptions; |
|
2
|
|
|
|
|
34
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _starting_points { |
48
|
1
|
50
|
|
1
|
|
41
|
return -e 'blib' ? 'blib' : 'lib'; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub all_metrics_ok { |
52
|
3
|
|
|
3
|
0
|
13
|
my @dirs = @_; |
53
|
|
|
|
|
|
|
|
54
|
3
|
|
|
|
|
12
|
Test::More::plan('no_plan'); |
55
|
|
|
|
|
|
|
|
56
|
3
|
100
|
|
|
|
15
|
if ( not @dirs ) { |
57
|
1
|
|
|
|
|
2
|
@dirs = _starting_points(); |
58
|
|
|
|
|
|
|
} |
59
|
3
|
|
|
|
|
9
|
my $files = all_code_files(@dirs); |
60
|
|
|
|
|
|
|
|
61
|
3
|
|
|
|
|
8
|
my $analysis = _analyze_metrics($files); |
62
|
3
|
|
|
|
|
26
|
my $ok = _all_files_metric_ok( $analysis->sub_stats ); |
63
|
3
|
|
|
|
|
496030
|
return $ok; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _analyze_metrics { |
67
|
3
|
|
|
3
|
|
8
|
my $libs = shift; |
68
|
3
|
|
|
|
|
28
|
my $analzyer = Perl::Metrics::Lite->new; |
69
|
3
|
|
|
|
|
162
|
my $analysis = $analzyer->analyze_files(@$libs); |
70
|
3
|
|
|
|
|
3564794
|
return $analysis; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _all_files_metric_ok { |
74
|
3
|
|
|
3
|
|
146
|
my $sub_stats = shift; |
75
|
3
|
|
|
|
|
8
|
my $ok = 0; |
76
|
3
|
|
|
|
|
7
|
foreach my $file_path ( keys %{$sub_stats} ) { |
|
3
|
|
|
|
|
16
|
|
77
|
5
|
100
|
|
|
|
11
|
my @except_files = @{ $METRICS_ARGS{-except_file} || [] }; |
|
5
|
|
|
|
|
48
|
|
78
|
5
|
100
|
|
|
|
22
|
next if is_excluded( $file_path, @except_files ); |
79
|
|
|
|
|
|
|
|
80
|
4
|
|
|
|
|
23
|
my $sub_metrics = $sub_stats->{$file_path}; |
81
|
4
|
50
|
|
|
|
20
|
$ok = $ok or _all_sub_metrics_ok($sub_metrics); |
82
|
|
|
|
|
|
|
} |
83
|
3
|
|
|
|
|
14
|
return $ok; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub _all_sub_metrics_ok { |
87
|
4
|
|
|
4
|
|
9
|
my $sub_metrics = shift; |
88
|
4
|
|
|
|
|
7
|
my @rows = (); |
89
|
4
|
|
|
|
|
8
|
my $ok = 0; |
90
|
4
|
|
|
|
|
8
|
foreach my $sub_metric ( @{$sub_metrics} ) { |
|
4
|
|
|
|
|
9
|
|
91
|
17
|
50
|
|
|
|
62
|
$ok = $ok or _sub_metric_ok($sub_metric); |
92
|
|
|
|
|
|
|
} |
93
|
4
|
|
|
|
|
15
|
return $ok; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _sub_metric_ok { |
97
|
17
|
|
|
17
|
|
25
|
my $sub_metric = shift; |
98
|
|
|
|
|
|
|
|
99
|
17
|
|
|
|
|
28
|
my $ok = 0; |
100
|
17
|
50
|
|
|
|
58
|
$ok = $ok or _sub_loc_ok($sub_metric); |
101
|
17
|
50
|
|
|
|
61
|
$ok = $ok or _sub_cc_ok($sub_metric); |
102
|
17
|
|
|
|
|
37
|
return $ok; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _sub_cc_ok { |
106
|
17
|
|
|
17
|
|
30
|
my $sub_metric = shift; |
107
|
|
|
|
|
|
|
|
108
|
17
|
|
|
|
|
80
|
my $cc = $sub_metric->{mccabe_complexity}; |
109
|
17
|
50
|
|
|
|
56
|
if ( $cc < $METRICS_ARGS{-mccabe_complexity} ) { |
110
|
17
|
|
|
|
|
85
|
$TEST->ok( 1, $sub_metric->{name} . " cc is ok" ); |
111
|
17
|
|
|
|
|
34
|
return 0; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
else { |
114
|
0
|
|
|
|
|
0
|
$TEST->ok( 0, |
115
|
|
|
|
|
|
|
"The method is to complex! Detail: Path: $sub_metric->{path}, Method: $sub_metric->{name}, CC: ${cc}" |
116
|
|
|
|
|
|
|
); |
117
|
0
|
|
|
|
|
0
|
return 1; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub _sub_loc_ok { |
122
|
17
|
|
|
17
|
|
26
|
my $sub_metric = shift; |
123
|
|
|
|
|
|
|
|
124
|
17
|
|
|
|
|
37
|
my $sloc = $sub_metric->{lines}; |
125
|
17
|
50
|
|
|
|
56
|
if ( $sloc < $METRICS_ARGS{-loc} ) { |
126
|
17
|
|
|
|
|
99
|
$TEST->ok( 1, $sub_metric->{name} . " sloc is ok" ); |
127
|
17
|
|
|
|
|
34
|
return 0; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
else { |
130
|
0
|
|
|
|
|
|
$TEST->ok( 0, |
131
|
|
|
|
|
|
|
"The method is too long! Detail: Path: $sub_metric->{path} ,Method: $sub_metric->{name}, SLOC: ${sloc}" |
132
|
|
|
|
|
|
|
); |
133
|
0
|
|
|
|
|
|
return 1; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
1; |
138
|
|
|
|
|
|
|
__END__ |