line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
4
|
|
|
4
|
|
59288
|
use 5.006; # our |
|
4
|
|
|
|
|
13
|
|
2
|
4
|
|
|
4
|
|
21
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
117
|
|
3
|
4
|
|
|
4
|
|
23
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
349
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package PPIx::DocumentName; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.001003'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: Utility to extract a name from a PPI Document |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY |
12
|
|
|
|
|
|
|
|
13
|
4
|
|
|
4
|
|
2184
|
use PPI::Util qw( _Document ); |
|
4
|
|
|
|
|
24432
|
|
|
4
|
|
|
|
|
736
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub log_info(&@); |
19
|
|
|
|
|
|
|
sub log_debug(&@); |
20
|
|
|
|
|
|
|
sub log_trace(&@); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
BEGIN { |
23
|
4
|
50
|
|
4
|
|
766
|
if ( $INC{'Log/Contextual.pm'} ) { |
24
|
|
|
|
|
|
|
## Hide from autoprereqs |
25
|
0
|
|
|
|
|
0
|
require 'Log/Contextual/WarnLogger.pm'; ## no critic (Modules::RequireBarewordIncludes) |
26
|
0
|
|
|
|
|
0
|
my $deflogger = Log::Contextual::WarnLogger->new( { env_prefix => 'PPIX_DOCUMENTNAME', } ); |
27
|
0
|
|
|
|
|
0
|
Log::Contextual->import( 'log_info', 'log_debug', 'log_trace', '-default_logger' => $deflogger ); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
else { |
30
|
4
|
|
|
|
|
740
|
require Carp; |
31
|
4
|
|
|
0
|
|
33
|
*log_info = sub (&@) { Carp::carp( $_[0]->() ) }; |
|
0
|
|
|
|
|
0
|
|
32
|
4
|
|
|
4
|
|
14
|
*log_debug = sub (&@) { }; |
33
|
4
|
|
|
2
|
|
1708
|
*log_trace = sub (&@) { }; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
## OO |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub extract { |
52
|
3
|
|
|
3
|
1
|
312184
|
my ( $self, $ppi_document ) = @_; |
53
|
3
|
|
66
|
|
|
13
|
my $docname = $self->extract_via_comment($ppi_document) |
54
|
|
|
|
|
|
|
|| $self->extract_via_statement($ppi_document); |
55
|
|
|
|
|
|
|
|
56
|
3
|
|
|
|
|
280
|
return $docname; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub extract_via_statement { |
71
|
5
|
|
|
5
|
1
|
1555
|
my ( undef, $ppi_document ) = @_; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Keep alive until done |
74
|
|
|
|
|
|
|
# https://github.com/adamkennedy/PPI/issues/112 |
75
|
5
|
|
|
|
|
13
|
my $dom = _Document($ppi_document); |
76
|
5
|
|
|
|
|
5110
|
my $pkg_node = $dom->find_first('PPI::Statement::Package'); |
77
|
5
|
50
|
|
|
|
873
|
if ( not $pkg_node ) { |
78
|
0
|
|
|
0
|
|
0
|
log_debug { "No PPI::Statement::Package found in <<$ppi_document>>" }; |
|
0
|
|
|
|
|
0
|
|
79
|
0
|
|
|
|
|
0
|
return; |
80
|
|
|
|
|
|
|
} |
81
|
5
|
50
|
|
|
|
24
|
if ( not $pkg_node->namespace ) { |
82
|
0
|
|
|
0
|
|
0
|
log_debug { "PPI::Statement::Package $pkg_node has empty namespace in <<$ppi_document>>" }; |
|
0
|
|
|
|
|
0
|
|
83
|
0
|
|
|
|
|
0
|
return; |
84
|
|
|
|
|
|
|
} |
85
|
5
|
|
|
|
|
135
|
return $pkg_node->namespace; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub extract_via_comment { |
100
|
6
|
|
|
6
|
1
|
1559
|
my ( undef, $ppi_document ) = @_; |
101
|
6
|
|
|
|
|
32
|
my $regex = qr{ ^ \s* \#+ \s* PODNAME: \s* (.+) $ }x; ## no critic (RegularExpressions) |
102
|
6
|
|
|
|
|
7
|
my $content; |
103
|
|
|
|
|
|
|
my $finder = sub { |
104
|
82
|
|
|
82
|
|
495
|
my $node = $_[1]; |
105
|
82
|
100
|
|
|
|
250
|
return 0 unless $node->isa('PPI::Token::Comment'); |
106
|
2
|
|
|
|
|
15
|
log_trace { "Found comment node $node" }; |
|
0
|
|
|
|
|
0
|
|
107
|
2
|
50
|
|
|
|
13
|
if ( $node->content =~ $regex ) { |
108
|
2
|
|
|
|
|
35
|
$content = $1; |
109
|
2
|
|
|
|
|
7
|
return 1; |
110
|
|
|
|
|
|
|
} |
111
|
0
|
|
|
|
|
0
|
return 0; |
112
|
6
|
|
|
|
|
32
|
}; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# Keep alive until done |
115
|
|
|
|
|
|
|
# https://github.com/adamkennedy/PPI/issues/112 |
116
|
6
|
|
|
|
|
18
|
my $dom = _Document($ppi_document); |
117
|
6
|
|
|
|
|
6304
|
$dom->find_first($finder); |
118
|
|
|
|
|
|
|
|
119
|
6
|
100
|
|
0
|
|
76
|
log_debug { "<<$ppi_document>> has no PODNAME comment" } if not $content; |
|
0
|
|
|
|
|
0
|
|
120
|
|
|
|
|
|
|
|
121
|
6
|
|
|
|
|
25
|
return $content; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |