| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
42
|
|
|
2
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
67
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Code::Statistics::Collector; |
|
5
|
|
|
|
|
|
|
{ |
|
6
|
|
|
|
|
|
|
$Code::Statistics::Collector::VERSION = '1.112980'; |
|
7
|
|
|
|
|
|
|
} |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: collects statistics and dumps them to json |
|
10
|
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
28
|
use 5.006_003; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
35
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
6
|
use Moose; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
8
|
|
|
14
|
1
|
|
|
1
|
|
7305
|
use MooseX::HasDefaults::RO; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
12
|
|
|
15
|
1
|
|
|
1
|
|
5925
|
use Code::Statistics::MooseTypes; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
57
|
|
|
16
|
1
|
|
|
1
|
|
1211
|
use MooseX::SlurpyConstructor 1.1; |
|
|
1
|
|
|
|
|
31296
|
|
|
|
1
|
|
|
|
|
7
|
|
|
17
|
1
|
|
|
1
|
|
61162
|
use Code::Statistics::Metric; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
6
|
|
|
18
|
1
|
|
|
1
|
|
532
|
use Code::Statistics::Target; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
41
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
1102
|
use File::Find::Rule::Perl; |
|
|
1
|
|
|
|
|
16937
|
|
|
|
1
|
|
|
|
|
15
|
|
|
21
|
1
|
|
|
1
|
|
516
|
use Code::Statistics::File; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
54
|
|
|
22
|
1
|
|
|
1
|
|
1294
|
use JSON 'to_json'; |
|
|
1
|
|
|
|
|
13366
|
|
|
|
1
|
|
|
|
|
7
|
|
|
23
|
1
|
|
|
1
|
|
200
|
use File::Slurp 'write_file'; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
78
|
|
|
24
|
1
|
|
|
1
|
|
1219
|
use Term::ProgressBar::Simple; |
|
|
1
|
|
|
|
|
162396
|
|
|
|
1
|
|
|
|
|
165
|
|
|
25
|
1
|
|
|
1
|
|
14
|
use File::Find::Rule; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
14
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has no_dump => ( isa => 'Bool' ); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has dirs => ( |
|
30
|
|
|
|
|
|
|
isa => 'CS::InputList', |
|
31
|
|
|
|
|
|
|
coerce => 1, |
|
32
|
|
|
|
|
|
|
default => sub { ['.'] }, |
|
33
|
|
|
|
|
|
|
); |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has files => ( |
|
36
|
|
|
|
|
|
|
isa => 'ArrayRef', |
|
37
|
|
|
|
|
|
|
lazy => 1, |
|
38
|
|
|
|
|
|
|
default => sub { |
|
39
|
|
|
|
|
|
|
return $_[0]->_prepare_files; |
|
40
|
|
|
|
|
|
|
}, |
|
41
|
|
|
|
|
|
|
); |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
has targets => ( |
|
44
|
|
|
|
|
|
|
isa => 'CS::InputList', |
|
45
|
|
|
|
|
|
|
coerce => 1, |
|
46
|
|
|
|
|
|
|
default => sub { $_[0]->_get_all_submodules_for('Target') }, |
|
47
|
|
|
|
|
|
|
); |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
has metrics => ( |
|
50
|
|
|
|
|
|
|
isa => 'CS::InputList', |
|
51
|
|
|
|
|
|
|
coerce => 1, |
|
52
|
|
|
|
|
|
|
default => sub { $_[0]->_get_all_submodules_for('Metric') }, |
|
53
|
|
|
|
|
|
|
); |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
has progress_bar => ( |
|
56
|
|
|
|
|
|
|
isa => 'Term::ProgressBar::Simple', |
|
57
|
|
|
|
|
|
|
lazy => 1, |
|
58
|
|
|
|
|
|
|
default => sub { |
|
59
|
|
|
|
|
|
|
my $params = { name => 'Files', ETA => 'linear', max_update_rate => '0.1' }; |
|
60
|
|
|
|
|
|
|
$params->{count} = @{ $_[0]->files }; |
|
61
|
|
|
|
|
|
|
return Term::ProgressBar::Simple->new( $params ); |
|
62
|
|
|
|
|
|
|
}, |
|
63
|
|
|
|
|
|
|
); |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
has command_args => ( |
|
66
|
|
|
|
|
|
|
is => 'ro', |
|
67
|
|
|
|
|
|
|
slurpy => 1, |
|
68
|
|
|
|
|
|
|
default => sub { {} }, |
|
69
|
|
|
|
|
|
|
); |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub collect { |
|
73
|
2
|
|
|
2
|
1
|
2304
|
my ( $self ) = @_; |
|
74
|
|
|
|
|
|
|
|
|
75
|
2
|
|
|
|
|
5
|
$_->analyze for @{ $self->files }; |
|
|
2
|
|
|
|
|
72
|
|
|
76
|
|
|
|
|
|
|
|
|
77
|
2
|
|
|
|
|
10
|
my $json = $self->_measurements_as_json; |
|
78
|
2
|
|
|
|
|
10
|
$self->_dump_file_measurements( $json ); |
|
79
|
|
|
|
|
|
|
|
|
80
|
2
|
|
|
|
|
114
|
return $json; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _find_files { |
|
84
|
2
|
|
|
2
|
|
4
|
my ( $self ) = @_; |
|
85
|
2
|
|
|
|
|
1908
|
my @files = ( |
|
86
|
2
|
|
|
|
|
2910
|
File::Find::Rule::Perl->perl_file->in( @{ $self->dirs } ), |
|
87
|
2
|
|
|
|
|
39
|
File::Find::Rule->file->name( '*.cgi' )->in( @{ $self->dirs } ), |
|
88
|
|
|
|
|
|
|
); |
|
89
|
2
|
|
|
|
|
1557
|
@files = sort { lc $a cmp lc $b } @files; |
|
|
10
|
|
|
|
|
24
|
|
|
90
|
2
|
|
|
|
|
10
|
return @files; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _prepare_files { |
|
94
|
2
|
|
|
2
|
|
4
|
my ( $self ) = @_; |
|
95
|
2
|
|
|
|
|
9
|
my @files = $self->_find_files; |
|
96
|
2
|
|
|
|
|
15
|
@files = map $self->_prepare_file( $_ ), @files; |
|
97
|
2
|
|
|
|
|
6569
|
return \@files; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub _prepare_file { |
|
101
|
8
|
|
|
8
|
|
20266
|
my ( $self, $path ) = @_; |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my %params = ( |
|
104
|
|
|
|
|
|
|
path => $path, |
|
105
|
|
|
|
|
|
|
original_path => $path, |
|
106
|
|
|
|
|
|
|
targets => $self->targets, |
|
107
|
|
|
|
|
|
|
metrics => $self->metrics, |
|
108
|
8
|
|
|
8
|
|
278
|
progress => sub { $self->progress_bar->increment }, |
|
109
|
8
|
|
|
|
|
299
|
); |
|
110
|
|
|
|
|
|
|
|
|
111
|
8
|
|
|
|
|
27
|
return Code::Statistics::File->new( %params, %{$self->command_args} ); |
|
|
8
|
|
|
|
|
272
|
|
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub _dump_file_measurements { |
|
115
|
2
|
|
|
2
|
|
15
|
my ( $self, $text ) = @_; |
|
116
|
2
|
100
|
|
|
|
76
|
return if $self->no_dump; |
|
117
|
|
|
|
|
|
|
|
|
118
|
1
|
|
|
|
|
10
|
write_file( 'codestat.out', $text ); |
|
119
|
|
|
|
|
|
|
|
|
120
|
1
|
|
|
|
|
471
|
return $self; |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub _measurements_as_json { |
|
124
|
2
|
|
|
2
|
|
5
|
my ( $self ) = @_; |
|
125
|
|
|
|
|
|
|
|
|
126
|
2
|
|
|
|
|
5
|
my @files = map $self->_strip_file( $_ ), @{ $self->files }; |
|
|
2
|
|
|
|
|
68
|
|
|
127
|
2
|
|
|
|
|
4
|
my @ignored_files = $self->_find_ignored_files( @{ $self->files } ); |
|
|
2
|
|
|
|
|
58
|
|
|
128
|
|
|
|
|
|
|
|
|
129
|
2
|
|
|
|
|
68
|
my $measurements = { |
|
130
|
|
|
|
|
|
|
files => \@files, |
|
131
|
|
|
|
|
|
|
targets => $self->targets, |
|
132
|
|
|
|
|
|
|
metrics => $self->metrics, |
|
133
|
|
|
|
|
|
|
ignored_files => \@ignored_files |
|
134
|
|
|
|
|
|
|
}; |
|
135
|
|
|
|
|
|
|
|
|
136
|
2
|
|
|
|
|
17
|
my $json = to_json( $measurements, { pretty => 1, canonical => 1 } ); |
|
137
|
|
|
|
|
|
|
|
|
138
|
2
|
|
|
|
|
386
|
return $json; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub _find_ignored_files { |
|
142
|
2
|
|
|
2
|
|
5
|
my ( $self, @files ) = @_; |
|
143
|
|
|
|
|
|
|
|
|
144
|
2
|
|
|
|
|
6
|
my %present_files = map { $_->{original_path} => 1 } @files; |
|
|
8
|
|
|
|
|
30
|
|
|
145
|
|
|
|
|
|
|
|
|
146
|
2
|
|
|
|
|
70
|
my @all_files = File::Find::Rule->file->in( @{ $self->dirs } ); |
|
|
2
|
|
|
|
|
164
|
|
|
147
|
2
|
|
|
|
|
1727
|
@all_files = grep { !$present_files{$_} } @all_files; |
|
|
8
|
|
|
|
|
20
|
|
|
148
|
2
|
|
|
|
|
11
|
my $useless_stuff = qr{ |
|
149
|
|
|
|
|
|
|
(^|/) |
|
150
|
|
|
|
|
|
|
( |
|
151
|
|
|
|
|
|
|
[.]git | [.]svn | cover_db | [.]build | nytprof | |
|
152
|
|
|
|
|
|
|
blib |
|
153
|
|
|
|
|
|
|
) |
|
154
|
|
|
|
|
|
|
/ |
|
155
|
|
|
|
|
|
|
}x; |
|
156
|
2
|
|
|
|
|
6
|
@all_files = grep { $_ !~ $useless_stuff } @all_files; # filter out files we most certainly do not care about |
|
|
0
|
|
|
|
|
0
|
|
|
157
|
|
|
|
|
|
|
|
|
158
|
2
|
|
|
|
|
9
|
return @all_files; |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub _strip_file { |
|
163
|
8
|
|
|
8
|
|
12
|
my ( $self, $file ) = @_; |
|
164
|
8
|
|
|
|
|
14
|
my %stripped_file = map { $_ => $file->{$_} } qw( path measurements ); |
|
|
16
|
|
|
|
|
51
|
|
|
165
|
8
|
|
|
|
|
26
|
return \%stripped_file; |
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub _get_all_submodules_for { |
|
169
|
4
|
|
|
4
|
|
12
|
my ( $self, $type ) = @_; |
|
170
|
4
|
|
|
|
|
14
|
my $class = "Code::Statistics::$type"; |
|
171
|
4
|
|
|
|
|
48
|
my @list = sort $class->all; |
|
172
|
|
|
|
|
|
|
|
|
173
|
4
|
|
|
|
|
41316
|
$_ =~ s/$class\::// for @list; |
|
174
|
|
|
|
|
|
|
|
|
175
|
4
|
|
|
|
|
26
|
my $all = join ';', @list; |
|
176
|
|
|
|
|
|
|
|
|
177
|
4
|
|
|
|
|
42
|
return $all; |
|
178
|
|
|
|
|
|
|
} |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
1; |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
__END__ |
|
183
|
|
|
|
|
|
|
=pod |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 NAME |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Code::Statistics::Collector - collects statistics and dumps them to json |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 VERSION |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
version 1.112980 |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head2 collect |
|
194
|
|
|
|
|
|
|
Locates files to collect statistics on, collects them and dumps them to |
|
195
|
|
|
|
|
|
|
JSON. |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head2 _strip_file |
|
198
|
|
|
|
|
|
|
Cuts down a file hash to have only the keys we actually want to dump to the |
|
199
|
|
|
|
|
|
|
json file. |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 AUTHOR |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Christian Walde <mithaldu@yahoo.de> |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
This software is Copyright (c) 2010 by Christian Walde. |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
This is free software, licensed under: |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE, Version 2, December 2004 |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=cut |
|
214
|
|
|
|
|
|
|
|