line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package EPublisher::Utils::PPI; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: PPI utility for EPublisher |
4
|
|
|
|
|
|
|
|
5
|
18
|
|
|
18
|
|
139559
|
use strict; |
|
18
|
|
|
|
|
61
|
|
|
18
|
|
|
|
|
546
|
|
6
|
18
|
|
|
18
|
|
94
|
use warnings; |
|
18
|
|
|
|
|
32
|
|
|
18
|
|
|
|
|
451
|
|
7
|
|
|
|
|
|
|
|
8
|
18
|
|
|
18
|
|
90
|
use Exporter; |
|
18
|
|
|
|
|
33
|
|
|
18
|
|
|
|
|
620
|
|
9
|
18
|
|
|
18
|
|
9495
|
use PPI; |
|
18
|
|
|
|
|
2247253
|
|
|
18
|
|
|
|
|
7445
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
14
|
|
|
|
|
|
|
extract_package |
15
|
|
|
|
|
|
|
extract_pod |
16
|
|
|
|
|
|
|
extract_pod_from_code |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = 0.5; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub extract_package { |
22
|
15
|
|
|
15
|
1
|
7873
|
my ($file, $config) = @_; |
23
|
|
|
|
|
|
|
|
24
|
15
|
100
|
100
|
|
|
359
|
return if !$file || !-r -f $file; |
25
|
|
|
|
|
|
|
|
26
|
11
|
|
|
|
|
435
|
open my $fh, '<', $file; |
27
|
|
|
|
|
|
|
|
28
|
11
|
100
|
|
|
|
54
|
if ( $config->{encoding} ) { |
29
|
1
|
|
|
2
|
|
35
|
binmode $fh, ':encoding(' . $config->{encoding} . ')'; |
|
2
|
|
|
|
|
18
|
|
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
17
|
|
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
11
|
|
|
|
|
11785
|
local $/; |
33
|
11
|
|
|
|
|
284
|
my $content = <$fh>; |
34
|
|
|
|
|
|
|
|
35
|
11
|
100
|
|
|
|
80
|
return if !$content; |
36
|
|
|
|
|
|
|
|
37
|
10
|
|
|
|
|
134
|
my $parser = PPI::Document->new( \$content ); |
38
|
|
|
|
|
|
|
|
39
|
10
|
100
|
|
|
|
107263
|
return if !$parser; |
40
|
|
|
|
|
|
|
|
41
|
9
|
|
|
|
|
49
|
my $stmt = $parser->find_first('PPI::Statement::Package'); |
42
|
|
|
|
|
|
|
|
43
|
9
|
100
|
|
|
|
23273
|
return if !$stmt; |
44
|
|
|
|
|
|
|
|
45
|
6
|
|
|
|
|
29
|
my $package = $stmt->namespace; |
46
|
|
|
|
|
|
|
|
47
|
6
|
|
|
|
|
234
|
return $package; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub extract_pod { |
51
|
98
|
|
|
98
|
1
|
8645
|
my ($file, $config) = @_; |
52
|
|
|
|
|
|
|
|
53
|
98
|
100
|
100
|
|
|
2613
|
return if !$file || !-r -f $file; |
54
|
|
|
|
|
|
|
|
55
|
94
|
|
|
|
|
293
|
my $content; |
56
|
|
|
|
|
|
|
|
57
|
94
|
|
|
|
|
4043
|
open my $fh, '<', $file; |
58
|
|
|
|
|
|
|
|
59
|
94
|
100
|
|
|
|
481
|
if ( $config->{encoding} ) { |
60
|
1
|
|
|
|
|
37
|
binmode $fh, ':encoding(' . $config->{encoding} . ')'; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
94
|
|
|
|
|
12495
|
local $/; |
64
|
94
|
|
|
|
|
4503
|
$content = <$fh>; |
65
|
94
|
|
|
|
|
1121
|
close $fh; |
66
|
|
|
|
|
|
|
|
67
|
94
|
|
|
|
|
420
|
return extract_pod_from_code( $content ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub extract_pod_from_code { |
71
|
94
|
|
|
94
|
1
|
274
|
my ($code) = @_; |
72
|
|
|
|
|
|
|
|
73
|
94
|
100
|
|
|
|
301
|
return if !$code; |
74
|
|
|
|
|
|
|
|
75
|
93
|
|
|
|
|
909
|
my $parser = PPI::Document->new( \$code ); |
76
|
|
|
|
|
|
|
|
77
|
93
|
100
|
|
|
|
3309026
|
return if !$parser; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $pod_nodes = $parser->find( |
80
|
|
|
|
|
|
|
sub { |
81
|
28951
|
|
|
28951
|
|
311096
|
$_[1]->isa( 'PPI::Token::Pod' ); |
82
|
|
|
|
|
|
|
}, |
83
|
92
|
|
|
|
|
836
|
); |
84
|
|
|
|
|
|
|
|
85
|
92
|
100
|
|
|
|
1421
|
my $merged = PPI::Token::Pod->merge( @{$pod_nodes || []} ); |
|
92
|
|
|
|
|
680
|
|
86
|
|
|
|
|
|
|
|
87
|
92
|
100
|
|
|
|
9909
|
return '' if !$merged; |
88
|
59
|
|
|
|
|
213
|
return $merged->content; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
__END__ |