line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Getopt::Config::FromPod; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
22183
|
use strict; |
|
6
|
|
|
|
|
510
|
|
|
6
|
|
|
|
|
225
|
|
4
|
6
|
|
|
6
|
|
33
|
use warnings; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
355
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Extract getopt configuration from POD |
7
|
|
|
|
|
|
|
our $VERSION = 'v0.0.2'; # VERSION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package Getopt::Config::FromPod::Extractor; |
10
|
|
|
|
|
|
|
|
11
|
6
|
|
|
6
|
|
37
|
use strict; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
172
|
|
12
|
6
|
|
|
6
|
|
29
|
use warnings; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
215
|
|
13
|
|
|
|
|
|
|
|
14
|
6
|
|
|
6
|
|
4906
|
use parent qw(Pod::Simple); |
|
6
|
|
|
|
|
1972
|
|
|
6
|
|
|
|
|
30
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new |
17
|
|
|
|
|
|
|
{ |
18
|
16
|
|
|
16
|
|
35
|
my ($ref, %args) = @_; |
19
|
16
|
|
33
|
|
|
89
|
my $class = ref $ref || $ref; |
20
|
16
|
|
|
|
|
64
|
my $self = bless Pod::Simple::new($class, %args), $class; |
21
|
16
|
|
100
|
|
|
505
|
my $tag = $args{-tag} || 'getopt'; |
22
|
16
|
|
|
|
|
68
|
$self->{_TAG} = $tag; |
23
|
16
|
|
|
|
|
75
|
$self->accept_targets($tag); |
24
|
16
|
|
|
|
|
279
|
return $self; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _handle_element_start |
28
|
|
|
|
|
|
|
{ |
29
|
292
|
|
|
292
|
|
46848
|
my ($parser, $element_name, $attr) = @_; |
30
|
292
|
100
|
|
|
|
653
|
if($element_name eq 'Document') { |
31
|
16
|
|
|
|
|
38
|
$parser->{_RESULT} = []; |
32
|
|
|
|
|
|
|
} |
33
|
292
|
100
|
66
|
|
|
1577
|
if(($element_name eq 'for' || $element_name eq 'begin') && $attr->{target} eq $parser->{_TAG}) { |
|
|
|
66
|
|
|
|
|
34
|
49
|
|
|
|
|
145
|
$parser->{_IN_TARGET} = 1; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _handle_element_end |
39
|
|
|
|
|
|
|
{ |
40
|
292
|
|
|
292
|
|
4068
|
my ($parser, $element_name, $attr) = @_; |
41
|
292
|
100
|
33
|
|
|
1189
|
if($element_name eq 'for' || ($element_name eq 'end' && $attr->{target} eq $parser->{_TAG})) { |
|
|
|
66
|
|
|
|
|
42
|
49
|
|
|
|
|
130
|
$parser->{_IN_TARGET} = 0; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _handle_text |
47
|
|
|
|
|
|
|
{ |
48
|
182
|
|
|
182
|
|
1310
|
my ($parser, $text) = @_; |
49
|
182
|
100
|
|
|
|
550
|
push @{$parser->{_RESULT}}, eval $text if $parser->{_IN_TARGET}; ## no critic (ProhibitStringyEval) |
|
49
|
|
|
|
|
3024
|
|
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
package Getopt::Config::FromPod; |
53
|
|
|
|
|
|
|
|
54
|
6
|
|
|
6
|
|
199686
|
use Carp; |
|
6
|
|
|
|
|
21
|
|
|
6
|
|
|
|
|
3939
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub new |
57
|
|
|
|
|
|
|
{ |
58
|
14
|
|
|
14
|
1
|
1649
|
my $self = shift; |
59
|
14
|
|
33
|
|
|
95
|
my $class = ref $self || $self; |
60
|
14
|
|
|
|
|
88
|
return bless { _ARG => \@_ }, $class; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub _extract |
64
|
|
|
|
|
|
|
{ |
65
|
16
|
|
|
16
|
|
32
|
my ($self, %args) = @_; |
66
|
16
|
|
|
|
|
21
|
%args = (@{$self->{_ARG}}, %args); |
|
16
|
|
|
|
|
70
|
|
67
|
16
|
|
|
|
|
99
|
my $parser = Getopt::Config::FromPod::Extractor->new(%args); |
68
|
16
|
|
|
|
|
45
|
my $file = $args{-file}; |
69
|
16
|
|
50
|
|
|
88
|
$args{-package} ||= 'main'; |
70
|
16
|
100
|
|
|
|
39
|
if(! defined $file) { |
71
|
8
|
|
|
|
|
15
|
my $idx = 0; |
72
|
8
|
|
|
|
|
9
|
my @caller; |
73
|
8
|
|
|
|
|
45
|
while(@caller = caller($idx++)) { |
74
|
22
|
100
|
|
|
|
480
|
if($caller[0] eq $args{-package}) { |
75
|
8
|
|
|
|
|
15
|
$file = $caller[1]; |
76
|
8
|
|
|
|
|
16
|
last; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
8
|
50
|
|
|
|
29
|
confess "Target module not found" if ! defined $file; |
80
|
|
|
|
|
|
|
# At least, in PAR environment, this adjustment is necessary. |
81
|
8
|
50
|
|
|
|
235
|
if(! -f $file) { |
82
|
0
|
|
|
|
|
0
|
for my $inc (@INC) { |
83
|
0
|
0
|
|
|
|
0
|
if(-f "$inc/$file") { |
84
|
0
|
|
|
|
|
0
|
$file = "$inc/$file"; |
85
|
0
|
|
|
|
|
0
|
last; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
16
|
50
|
66
|
|
|
253
|
croak "Target file not found: $file" if ref $file eq '' && ! -f $file; |
91
|
16
|
|
|
|
|
89
|
$parser->parse_file($file); |
92
|
16
|
|
|
|
|
1622
|
return $parser->{_RESULT}; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $SELF = __PACKAGE__->new; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub __ref |
98
|
|
|
|
|
|
|
{ |
99
|
30
|
|
|
30
|
|
51
|
my $ref = shift; |
100
|
30
|
100
|
|
|
|
96
|
return if ref $ref->[0]; |
101
|
6
|
50
|
|
|
|
9
|
croak 'Calling as neither instance method nor class method' unless eval { $ref->[0]->isa(__PACKAGE__) }; |
|
6
|
|
|
|
|
56
|
|
102
|
6
|
|
|
|
|
20
|
splice @$ref, 0, 1, $SELF; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub string |
106
|
|
|
|
|
|
|
{ |
107
|
6
|
|
|
6
|
1
|
4298
|
__ref(\@_); |
108
|
6
|
|
|
|
|
16
|
my ($self, %args) = @_; |
109
|
6
|
100
|
|
|
|
45
|
return join(exists $args{-separator} ? $args{-separator} : '', $self->array(%args)); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub array |
113
|
|
|
|
|
|
|
{ |
114
|
16
|
|
|
16
|
1
|
43
|
__ref(\@_); |
115
|
16
|
|
|
|
|
36
|
my ($self, %args) = @_; |
116
|
16
|
|
|
|
|
20
|
return @{$self->_extract(%args)}; |
|
16
|
|
|
|
|
44
|
|
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub arrayref |
120
|
|
|
|
|
|
|
{ |
121
|
4
|
|
|
4
|
1
|
20
|
__ref(\@_); |
122
|
4
|
|
|
|
|
13
|
my ($self, %args) = @_; |
123
|
4
|
|
|
|
|
23
|
return [$self->array(%args)]; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub hashref |
127
|
|
|
|
|
|
|
{ |
128
|
4
|
|
|
4
|
1
|
17
|
__ref(\@_); |
129
|
4
|
|
|
|
|
10
|
my ($self, %args) = @_; |
130
|
4
|
|
|
|
|
17
|
return {$self->array(%args)}; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub set_class_default |
134
|
|
|
|
|
|
|
{ |
135
|
2
|
|
|
2
|
1
|
2480
|
my ($self, %args) = @_; |
136
|
2
|
|
|
|
|
11
|
$SELF = __PACKAGE__->new(%args); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
1; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
__END__ |