| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Test::UsedModules::PPIDocument; |
|
2
|
26
|
|
|
26
|
|
158
|
use strict; |
|
|
26
|
|
|
|
|
43
|
|
|
|
26
|
|
|
|
|
962
|
|
|
3
|
26
|
|
|
26
|
|
165
|
use warnings; |
|
|
26
|
|
|
|
|
57
|
|
|
|
26
|
|
|
|
|
787
|
|
|
4
|
26
|
|
|
26
|
|
141
|
use utf8; |
|
|
26
|
|
|
|
|
57
|
|
|
|
26
|
|
|
|
|
626
|
|
|
5
|
26
|
|
|
26
|
|
25191
|
use PPI::Document; |
|
|
26
|
|
|
|
|
4331613
|
|
|
|
26
|
|
|
|
|
931
|
|
|
6
|
26
|
|
|
26
|
|
21394
|
use PPI::Dumper; |
|
|
26
|
|
|
|
|
28520
|
|
|
|
26
|
|
|
|
|
854
|
|
|
7
|
26
|
|
|
26
|
|
13801
|
use Test::UsedModules::Constants; |
|
|
26
|
|
|
|
|
72
|
|
|
|
26
|
|
|
|
|
22443
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub generate { |
|
10
|
42
|
|
|
42
|
0
|
514
|
my ($file, $extra_remove_token) = shift; |
|
11
|
|
|
|
|
|
|
|
|
12
|
42
|
|
|
|
|
884
|
my $document = _generate_with_include($file, $extra_remove_token); |
|
13
|
42
|
|
|
|
|
127129
|
return _remove_include_sections($document); |
|
14
|
|
|
|
|
|
|
} |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub fetch_modules_in_module { |
|
17
|
21
|
|
|
21
|
0
|
92
|
my ($file) = @_; |
|
18
|
21
|
|
|
|
|
113
|
my $ppi_document = _generate_with_include($file); |
|
19
|
21
|
|
|
|
|
68412
|
my @ppi_used_modules = _list_up_modules($ppi_document); |
|
20
|
|
|
|
|
|
|
|
|
21
|
21
|
|
|
|
|
50
|
my @used_modules; |
|
22
|
21
|
|
|
|
|
190
|
for my $ppi_used_module (@ppi_used_modules) { |
|
23
|
91
|
|
|
|
|
116
|
my $used_module; |
|
24
|
91
|
|
|
|
|
1003
|
( $used_module->{type}, $used_module->{name} ) = $ppi_used_module =~ / |
|
25
|
|
|
|
|
|
|
\s*? PPI::Token::Word \s* \'(use|require|load)\' \n |
|
26
|
|
|
|
|
|
|
\s*? PPI::Token::Word \s* \'(.*?)\' \n |
|
27
|
|
|
|
|
|
|
/gxm; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Reduce pragmas |
|
30
|
91
|
100
|
|
|
|
393
|
next if grep { $_ eq $used_module->{name} } PRAGMAS; |
|
|
3549
|
|
|
|
|
6463
|
|
|
31
|
|
|
|
|
|
|
|
|
32
|
25
|
|
|
|
|
3227
|
( $used_module->{extend} ) = $ppi_used_module =~ / |
|
33
|
|
|
|
|
|
|
\s*? PPI::Token::Word \s* .*? |
|
34
|
|
|
|
|
|
|
\s*? PPI::Token::Word \s* .*? |
|
35
|
|
|
|
|
|
|
\s*? PPI::\S* \s* \'?(.*?)\'? \n |
|
36
|
|
|
|
|
|
|
/gxm; |
|
37
|
|
|
|
|
|
|
|
|
38
|
25
|
|
|
|
|
113
|
push @used_modules, $used_module; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
21
|
|
|
|
|
201
|
return @used_modules; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _list_up_modules { |
|
45
|
21
|
|
|
21
|
|
10999
|
my ($ppi_document) = @_; |
|
46
|
|
|
|
|
|
|
|
|
47
|
21
|
|
|
|
|
708
|
my @ppi_used_modules = $ppi_document =~ / |
|
48
|
|
|
|
|
|
|
PPI::Statement::Include \n |
|
49
|
|
|
|
|
|
|
( |
|
50
|
|
|
|
|
|
|
\s*? PPI::Token::Word \s* \'(?:use|require)\' \s*? \n |
|
51
|
|
|
|
|
|
|
\s*? PPI::Token::Word \s* .*? \n |
|
52
|
|
|
|
|
|
|
(?:.*? \n)? |
|
53
|
|
|
|
|
|
|
) |
|
54
|
|
|
|
|
|
|
\s*? PPI::Token::Structure \s* \';\' \s*? \n |
|
55
|
|
|
|
|
|
|
/gxm; |
|
56
|
|
|
|
|
|
|
|
|
57
|
21
|
|
|
|
|
394
|
my @ppi_loaded_modules = $ppi_document =~ / |
|
58
|
|
|
|
|
|
|
PPI::Statement \n |
|
59
|
|
|
|
|
|
|
( |
|
60
|
|
|
|
|
|
|
\s*? PPI::Token::Word \s* \'load\' \s*? \n |
|
61
|
|
|
|
|
|
|
\s*? PPI::Token::Word \s* .*? \n |
|
62
|
|
|
|
|
|
|
(?:.*? \n)? |
|
63
|
|
|
|
|
|
|
) |
|
64
|
|
|
|
|
|
|
\s*? PPI::Token::Structure \s* \';\' \s*? \n |
|
65
|
|
|
|
|
|
|
/gxm; |
|
66
|
|
|
|
|
|
|
|
|
67
|
21
|
|
|
|
|
182
|
push @ppi_used_modules, @ppi_loaded_modules; |
|
68
|
|
|
|
|
|
|
|
|
69
|
21
|
|
|
|
|
146
|
return @ppi_used_modules; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub _generate_with_include { |
|
73
|
63
|
|
|
63
|
|
404
|
my ($file, $extra_remove_token) = shift; |
|
74
|
|
|
|
|
|
|
|
|
75
|
63
|
|
|
|
|
3093
|
my $document = _remove_unnecessary_tokens(PPI::Document->new($file), $extra_remove_token); |
|
76
|
63
|
|
|
|
|
1840
|
return PPI::Dumper->new($document)->string(); |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _remove_include_sections { |
|
80
|
42
|
|
|
42
|
|
22600
|
my ($ppi_document) = @_; |
|
81
|
42
|
|
|
|
|
1941
|
$ppi_document =~ s/ |
|
82
|
|
|
|
|
|
|
PPI::Statement::Include \n |
|
83
|
|
|
|
|
|
|
\s*? PPI::Token::Word \s* \'(?:use|require)\' \s*? \n |
|
84
|
|
|
|
|
|
|
\s*? PPI::Token::Word \s* .*? \n |
|
85
|
|
|
|
|
|
|
(?:.*? \n)? |
|
86
|
|
|
|
|
|
|
\s*? PPI::Token::Structure \s* \';\' \s*? \n |
|
87
|
|
|
|
|
|
|
//gxm; |
|
88
|
42
|
|
|
|
|
353
|
my $load_removed = $ppi_document =~ s/ |
|
89
|
|
|
|
|
|
|
PPI::Statement \n |
|
90
|
|
|
|
|
|
|
\s*? PPI::Token::Word \s* \'load\' \s*? \n |
|
91
|
|
|
|
|
|
|
\s*? PPI::Token::Word \s* .*? \n |
|
92
|
|
|
|
|
|
|
(?:.*? \n)? |
|
93
|
|
|
|
|
|
|
\s*? PPI::Token::Structure \s* \';\' \s*? \n |
|
94
|
|
|
|
|
|
|
//gxm; |
|
95
|
42
|
|
|
|
|
390
|
return ($ppi_document, $load_removed); |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub _remove_unnecessary_tokens { |
|
99
|
63
|
|
|
63
|
|
971466
|
my ( $document, $optional_token ) = @_; |
|
100
|
|
|
|
|
|
|
|
|
101
|
63
|
|
|
|
|
1300
|
my @surplus_tokens = ( |
|
102
|
|
|
|
|
|
|
'Operator', |
|
103
|
|
|
|
|
|
|
'Number', |
|
104
|
|
|
|
|
|
|
'Comment', |
|
105
|
|
|
|
|
|
|
'Pod', |
|
106
|
|
|
|
|
|
|
'BOM', |
|
107
|
|
|
|
|
|
|
'Data', |
|
108
|
|
|
|
|
|
|
'End', |
|
109
|
|
|
|
|
|
|
'Prototype', |
|
110
|
|
|
|
|
|
|
'Separator', |
|
111
|
|
|
|
|
|
|
'Whitespace' |
|
112
|
|
|
|
|
|
|
); |
|
113
|
|
|
|
|
|
|
|
|
114
|
63
|
50
|
|
|
|
1151
|
if ($optional_token) { |
|
115
|
0
|
|
|
|
|
0
|
push @surplus_tokens, $optional_token; |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
63
|
|
|
|
|
176
|
foreach my $surplus_token (@surplus_tokens) { |
|
119
|
630
|
|
|
|
|
2303133
|
$document->prune( 'PPI::Token::' . $surplus_token ); |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
63
|
|
|
|
|
349200
|
return $document; |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
1; |