line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::Metrics::Lite::Analysis::DocumentFactory; |
2
|
5
|
|
|
5
|
|
3413
|
use strict; |
|
5
|
|
|
|
|
18
|
|
|
5
|
|
|
|
|
153
|
|
3
|
5
|
|
|
5
|
|
25
|
use warnings; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
115
|
|
4
|
5
|
|
|
5
|
|
2760
|
use PPI; |
|
5
|
|
|
|
|
593524
|
|
|
5
|
|
|
|
|
192
|
|
5
|
5
|
|
|
5
|
|
46
|
use PPI::Document; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
131
|
|
6
|
5
|
|
|
5
|
|
490
|
use Perl::Metrics::Lite::Analysis::Util; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
145
|
|
7
|
|
|
|
|
|
|
|
8
|
5
|
|
|
5
|
|
29
|
use Carp qw(confess); |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
1240
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub create_normalized_document { |
11
|
19
|
|
|
19
|
0
|
1134
|
my ( $class, $path ) = @_; |
12
|
|
|
|
|
|
|
|
13
|
19
|
|
|
|
|
42
|
my $document; |
14
|
19
|
50
|
|
|
|
59
|
if ( ref $path ) { |
15
|
0
|
0
|
|
|
|
0
|
if ( ref $path eq 'SCALAR' ) { |
16
|
0
|
|
|
|
|
0
|
$document = PPI::Document->new($path); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
else { |
19
|
0
|
|
|
|
|
0
|
$document = $path; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
else { |
23
|
19
|
50
|
|
|
|
877
|
if ( !-r $path ) { |
24
|
0
|
|
|
|
|
0
|
Carp::confess "Path '$path' is missing or not readable!"; |
25
|
|
|
|
|
|
|
} |
26
|
19
|
|
|
|
|
104
|
$document = _create_ppi_document($path); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
19
|
|
|
|
|
99
|
$document; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _create_ppi_document { |
33
|
19
|
|
|
19
|
|
45
|
my $path = shift; |
34
|
19
|
|
|
|
|
36
|
my $document; |
35
|
19
|
100
|
|
|
|
269
|
if ( -s $path ) { |
36
|
17
|
|
|
|
|
178
|
$document = PPI::Document->new($path); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
else { |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# The file is empty. Create a PPI document with a single whitespace |
41
|
|
|
|
|
|
|
# chararacter. This makes sure that the PPI tokens() method |
42
|
|
|
|
|
|
|
# returns something, so we avoid a warning from |
43
|
|
|
|
|
|
|
# PPI::Document::index_locations() which expects tokens() to return |
44
|
|
|
|
|
|
|
# something other than undef. |
45
|
2
|
|
|
|
|
9
|
my $one_whitespace_character = q{ }; |
46
|
2
|
|
|
|
|
20
|
$document = PPI::Document->new( \$one_whitespace_character ); |
47
|
|
|
|
|
|
|
} |
48
|
19
|
|
|
|
|
249851
|
return $document; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _make_pruned_document { |
52
|
0
|
|
|
0
|
|
|
my $document = shift; |
53
|
0
|
|
|
|
|
|
$document = Perl::Metrics::Lite::Analysis::Util::prune_non_code_lines($document); |
54
|
0
|
|
|
|
|
|
$document->index_locations(); |
55
|
0
|
|
|
|
|
|
$document->readonly(1); |
56
|
0
|
|
|
|
|
|
return $document; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |