line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Getopt::Config::FromPod; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
24234
|
use strict; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
172
|
|
4
|
6
|
|
|
6
|
|
34
|
use warnings; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
299
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Extract getopt configuration from POD |
7
|
|
|
|
|
|
|
our $VERSION = 'v0.0.4'; # VERSION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package Getopt::Config::FromPod::Extractor; |
10
|
|
|
|
|
|
|
|
11
|
6
|
|
|
6
|
|
37
|
use strict; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
136
|
|
12
|
6
|
|
|
6
|
|
35
|
use warnings; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
192
|
|
13
|
|
|
|
|
|
|
|
14
|
6
|
|
|
6
|
|
2594
|
use parent qw(Pod::Simple); |
|
6
|
|
|
|
|
1888
|
|
|
6
|
|
|
|
|
31
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new |
17
|
|
|
|
|
|
|
{ |
18
|
16
|
|
|
16
|
|
95
|
my ($ref, %args) = @_; |
19
|
16
|
|
33
|
|
|
111
|
my $class = ref $ref || $ref; |
20
|
16
|
|
|
|
|
74
|
my $self = bless Pod::Simple::new($class, %args), $class; |
21
|
16
|
|
100
|
|
|
454
|
my $tag = $args{-tag} || 'getopt'; |
22
|
16
|
|
|
|
|
74
|
$self->{_TAG} = $tag; |
23
|
16
|
|
|
|
|
87
|
$self->accept_targets($tag); |
24
|
16
|
|
|
|
|
323
|
return $self; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _handle_element_start |
28
|
|
|
|
|
|
|
{ |
29
|
292
|
|
|
292
|
|
65813
|
my ($parser, $element_name, $attr) = @_; |
30
|
292
|
100
|
|
|
|
774
|
if($element_name eq 'Document') { |
31
|
16
|
|
|
|
|
64
|
$parser->{_RESULT} = []; |
32
|
|
|
|
|
|
|
} |
33
|
292
|
100
|
66
|
|
|
1392
|
if(($element_name eq 'for' || $element_name eq 'begin') && $attr->{target} eq $parser->{_TAG}) { |
|
|
|
66
|
|
|
|
|
34
|
49
|
|
|
|
|
144
|
$parser->{_IN_TARGET} = 1; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _handle_element_end |
39
|
|
|
|
|
|
|
{ |
40
|
292
|
|
|
292
|
|
5593
|
my ($parser, $element_name, $attr) = @_; |
41
|
292
|
100
|
33
|
|
|
1244
|
if($element_name eq 'for' || ($element_name eq 'end' && $attr->{target} eq $parser->{_TAG})) { |
|
|
|
100
|
|
|
|
|
42
|
49
|
|
|
|
|
146
|
$parser->{_IN_TARGET} = 0; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _handle_text |
47
|
|
|
|
|
|
|
{ |
48
|
182
|
|
|
182
|
|
1718
|
my ($parser, $text) = @_; |
49
|
182
|
100
|
|
|
|
531
|
push @{$parser->{_RESULT}}, eval $text if $parser->{_IN_TARGET}; ## no critic (ProhibitStringyEval) |
|
49
|
|
|
|
|
2873
|
|
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
package Getopt::Config::FromPod; |
53
|
|
|
|
|
|
|
|
54
|
6
|
|
|
6
|
|
194584
|
use Carp; |
|
6
|
|
|
|
|
21
|
|
|
6
|
|
|
|
|
4758
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub new |
57
|
|
|
|
|
|
|
{ |
58
|
14
|
|
|
14
|
1
|
2327
|
my $self = shift; |
59
|
14
|
|
33
|
|
|
84
|
my $class = ref $self || $self; |
60
|
14
|
|
|
|
|
101
|
return bless { _ARG => \@_ }, $class; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub _extract |
64
|
|
|
|
|
|
|
{ |
65
|
16
|
|
|
16
|
|
42
|
my ($self, %args) = @_; |
66
|
16
|
|
|
|
|
43
|
%args = (@{$self->{_ARG}}, %args); |
|
16
|
|
|
|
|
80
|
|
67
|
16
|
|
|
|
|
99
|
my $parser = Getopt::Config::FromPod::Extractor->new(%args); |
68
|
16
|
|
|
|
|
40
|
my $file = $args{-file}; |
69
|
16
|
|
50
|
|
|
106
|
$args{-package} ||= 'main'; |
70
|
16
|
100
|
|
|
|
52
|
if(! defined $file) { |
71
|
8
|
|
|
|
|
17
|
my $idx = 0; |
72
|
8
|
|
|
|
|
16
|
my @caller; |
73
|
8
|
|
|
|
|
43
|
while(@caller = caller($idx++)) { |
74
|
22
|
100
|
|
|
|
517
|
if($caller[0] eq $args{-package}) { |
75
|
8
|
|
|
|
|
21
|
$file = $caller[1]; |
76
|
8
|
|
|
|
|
18
|
last; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
8
|
50
|
|
|
|
28
|
confess "Target module not found" if ! defined $file; |
80
|
|
|
|
|
|
|
# At least, in PAR environment, this adjustment is necessary. |
81
|
8
|
50
|
|
|
|
191
|
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
|
|
|
251
|
croak "Target file not found: $file" if ref $file eq '' && ! -f $file; |
91
|
16
|
|
|
|
|
113
|
$parser->parse_file($file); |
92
|
16
|
|
|
|
|
708
|
return $parser->{_RESULT}; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $SELF = __PACKAGE__->new; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub __ref |
98
|
|
|
|
|
|
|
{ |
99
|
30
|
|
|
30
|
|
60
|
my $ref = shift; |
100
|
30
|
100
|
|
|
|
101
|
return if ref $ref->[0]; |
101
|
6
|
50
|
|
|
|
10
|
croak 'Calling as neither instance method nor class method' unless eval { $ref->[0]->isa(__PACKAGE__) }; |
|
6
|
|
|
|
|
36
|
|
102
|
6
|
|
|
|
|
17
|
splice @$ref, 0, 1, $SELF; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub string |
106
|
|
|
|
|
|
|
{ |
107
|
6
|
|
|
6
|
1
|
3212
|
__ref(\@_); |
108
|
6
|
|
|
|
|
19
|
my ($self, %args) = @_; |
109
|
6
|
100
|
|
|
|
33
|
return join(exists $args{-separator} ? $args{-separator} : '', $self->array(%args)); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub array |
113
|
|
|
|
|
|
|
{ |
114
|
16
|
|
|
16
|
1
|
58
|
__ref(\@_); |
115
|
16
|
|
|
|
|
43
|
my ($self, %args) = @_; |
116
|
16
|
|
|
|
|
34
|
return @{$self->_extract(%args)}; |
|
16
|
|
|
|
|
70
|
|
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub arrayref |
120
|
|
|
|
|
|
|
{ |
121
|
4
|
|
|
4
|
1
|
19
|
__ref(\@_); |
122
|
4
|
|
|
|
|
14
|
my ($self, %args) = @_; |
123
|
4
|
|
|
|
|
18
|
return [$self->array(%args)]; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub hashref |
127
|
|
|
|
|
|
|
{ |
128
|
4
|
|
|
4
|
1
|
21
|
__ref(\@_); |
129
|
4
|
|
|
|
|
11
|
my ($self, %args) = @_; |
130
|
4
|
|
|
|
|
18
|
return {$self->array(%args)}; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub set_class_default |
134
|
|
|
|
|
|
|
{ |
135
|
2
|
|
|
2
|
1
|
1466
|
my ($self, %args) = @_; |
136
|
2
|
|
|
|
|
12
|
$SELF = __PACKAGE__->new(%args); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
1; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
__END__ |