| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#============================================================= -*-Perl-*- |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# Pod::POM |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# DESCRIPTION |
|
6
|
|
|
|
|
|
|
# Parses POD from a file or text string and builds a tree structure, |
|
7
|
|
|
|
|
|
|
# hereafter known as the POD Object Model (POM). |
|
8
|
|
|
|
|
|
|
# |
|
9
|
|
|
|
|
|
|
# AUTHOR |
|
10
|
|
|
|
|
|
|
# Andy Wardley |
|
11
|
|
|
|
|
|
|
# |
|
12
|
|
|
|
|
|
|
# Andrew Ford (co-maintainer as of 03/2009) |
|
13
|
|
|
|
|
|
|
# |
|
14
|
|
|
|
|
|
|
# COPYRIGHT |
|
15
|
|
|
|
|
|
|
# Copyright (C) 2000-2009 Andy Wardley. All Rights Reserved. |
|
16
|
|
|
|
|
|
|
# Copyright (C) 2009 Andrew Ford. All Rights Reserved. |
|
17
|
|
|
|
|
|
|
# |
|
18
|
|
|
|
|
|
|
# This module is free software; you can redistribute it and/or |
|
19
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
|
20
|
|
|
|
|
|
|
# |
|
21
|
|
|
|
|
|
|
# REVISION |
|
22
|
|
|
|
|
|
|
# $Id: POM.pm 91 2013-12-31 07:36:02Z ford $ |
|
23
|
|
|
|
|
|
|
# |
|
24
|
|
|
|
|
|
|
#======================================================================== |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
package Pod::POM; |
|
27
|
|
|
|
|
|
|
$Pod::POM::VERSION = '2.00'; |
|
28
|
|
|
|
|
|
|
require 5.006; |
|
29
|
|
|
|
|
|
|
|
|
30
|
18
|
|
|
18
|
|
69881
|
use strict; |
|
|
18
|
|
|
|
|
29
|
|
|
|
18
|
|
|
|
|
453
|
|
|
31
|
18
|
|
|
18
|
|
84
|
use warnings; |
|
|
18
|
|
|
|
|
29
|
|
|
|
18
|
|
|
|
|
549
|
|
|
32
|
|
|
|
|
|
|
|
|
33
|
18
|
|
|
18
|
|
7304
|
use Pod::POM::Constants qw( :all ); |
|
|
18
|
|
|
|
|
41
|
|
|
|
18
|
|
|
|
|
2703
|
|
|
34
|
18
|
|
|
18
|
|
8120
|
use Pod::POM::Nodes; |
|
|
18
|
|
|
|
|
41
|
|
|
|
18
|
|
|
|
|
733
|
|
|
35
|
18
|
|
|
18
|
|
7385
|
use Pod::POM::View::Pod; |
|
|
18
|
|
|
|
|
42
|
|
|
|
18
|
|
|
|
|
591
|
|
|
36
|
|
|
|
|
|
|
|
|
37
|
18
|
|
|
18
|
|
79
|
use parent qw( Exporter ); |
|
|
18
|
|
|
|
|
25
|
|
|
|
18
|
|
|
|
|
65
|
|
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
our $DEBUG = 0 unless defined $DEBUG; |
|
40
|
|
|
|
|
|
|
our $ROOT = 'Pod::POM::Node::Pod'; # root node class |
|
41
|
|
|
|
|
|
|
our $TEXTSEQ = 'Pod::POM::Node::Sequence'; # text sequence class |
|
42
|
|
|
|
|
|
|
our $DEFAULT_VIEW = 'Pod::POM::View::Pod'; # default view class |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
46
|
|
|
|
|
|
|
# allow 'meta' to be specified as a load option to activate =meta tags |
|
47
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
our @EXPORT_OK = qw( meta ); |
|
50
|
|
|
|
|
|
|
our @EXPORT_FAIL = qw( meta ); |
|
51
|
|
|
|
|
|
|
our $ALLOW_META = 0; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub export_fail { |
|
54
|
1
|
|
|
1
|
0
|
85
|
my $class = shift; |
|
55
|
1
|
|
|
|
|
2
|
my $meta = shift; |
|
56
|
1
|
50
|
|
|
|
4
|
return ($meta, @_) unless $meta eq 'meta'; |
|
57
|
1
|
|
|
|
|
1
|
$ALLOW_META++; |
|
58
|
1
|
|
|
|
|
38
|
return @_; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
64
|
|
|
|
|
|
|
# new(\%options) |
|
65
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub new { |
|
68
|
21
|
|
|
21
|
1
|
54393
|
my $class = shift; |
|
69
|
21
|
50
|
|
|
|
206
|
my $config = ref $_[0] eq 'HASH' ? shift : { @_ }; |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
bless { |
|
72
|
|
|
|
|
|
|
CODE => $config->{ code } || 0, |
|
73
|
|
|
|
|
|
|
WARN => $config->{ warn } || 0, |
|
74
|
21
|
|
100
|
|
|
425
|
META => $config->{ meta } || $ALLOW_META, |
|
|
|
|
100
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
75
|
|
|
|
|
|
|
WARNINGS => [ ], |
|
76
|
|
|
|
|
|
|
FILENAME => '', |
|
77
|
|
|
|
|
|
|
ERROR => '', |
|
78
|
|
|
|
|
|
|
}, $class; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
83
|
|
|
|
|
|
|
# parse($text_or_file) |
|
84
|
|
|
|
|
|
|
# |
|
85
|
|
|
|
|
|
|
# General purpose parse method which attempts to Do The Right Thing in |
|
86
|
|
|
|
|
|
|
# calling parse_file() or parse_text() according to the argument |
|
87
|
|
|
|
|
|
|
# passed. A hash reference can be specified that contains a 'text' |
|
88
|
|
|
|
|
|
|
# or 'file' key and corresponding value. Otherwise, the argument can |
|
89
|
|
|
|
|
|
|
# be a reference to an input handle which is passed off to parse_file(). |
|
90
|
|
|
|
|
|
|
# If the argument is a text string that contains '=' at the start of |
|
91
|
|
|
|
|
|
|
# any line then it is treated as Pod text and passed to parse_text(), |
|
92
|
|
|
|
|
|
|
# otherwise it is assumed to be a filename and passed to parse_file(). |
|
93
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub parse { |
|
96
|
0
|
|
|
0
|
1
|
0
|
my ($self, $input) = @_; |
|
97
|
0
|
|
|
|
|
0
|
my $result; |
|
98
|
|
|
|
|
|
|
|
|
99
|
0
|
0
|
0
|
|
|
0
|
if (ref $input eq 'HASH') { |
|
|
|
0
|
|
|
|
|
|
|
100
|
0
|
0
|
|
|
|
0
|
if ($input = $input->{ text }) { |
|
|
|
0
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
0
|
$result = $self->parse_text($input, $input->{ name }); |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
elsif ($input = $input->{ file }) { |
|
104
|
0
|
|
|
|
|
0
|
$result = $self->parse_file($input); |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
else { |
|
107
|
0
|
|
|
|
|
0
|
$result = $self->error("no 'text' or 'file' specified"); |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
elsif (ref $input || $input !~ /^=/m) { # doesn't look like POD text |
|
111
|
0
|
|
|
|
|
0
|
$result = $self->parse_file($input); |
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
else { # looks like POD text |
|
114
|
0
|
|
|
|
|
0
|
$result = $self->parse_text($input); |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
0
|
return $result; |
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
122
|
|
|
|
|
|
|
# parse_file($filename_or_handle) |
|
123
|
|
|
|
|
|
|
# |
|
124
|
|
|
|
|
|
|
# Reads the content of a Pod file specified by name or file handle, and |
|
125
|
|
|
|
|
|
|
# passes it to parse_text() for parsing. |
|
126
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub parse_file { |
|
129
|
5
|
|
|
5
|
1
|
37
|
my ($self, $file) = @_; |
|
130
|
5
|
|
|
|
|
8
|
my ($text, $name); |
|
131
|
|
|
|
|
|
|
|
|
132
|
5
|
100
|
|
|
|
34
|
if (ref $file) { # assume open filehandle |
|
133
|
4
|
|
|
|
|
330
|
local $/ = undef; |
|
134
|
4
|
|
|
|
|
10
|
$name = ''; |
|
135
|
4
|
|
|
|
|
70
|
$text = <$file>; |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
else { # a file which must be opened |
|
138
|
1
|
|
|
|
|
2
|
local *FP; |
|
139
|
1
|
|
|
|
|
3
|
local $/ = undef; |
|
140
|
1
|
50
|
|
|
|
5
|
$name = ( $file eq '-' ? '' : $file ); |
|
141
|
1
|
50
|
|
|
|
27
|
open(FP, $file) || return $self->error("$file: $!"); |
|
142
|
1
|
|
|
|
|
25
|
$text = ; |
|
143
|
1
|
|
|
|
|
8
|
close(FP); |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
|
|
146
|
5
|
|
|
|
|
37
|
$self->parse_text($text, $name); |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
151
|
|
|
|
|
|
|
# parse_text($text, $name) |
|
152
|
|
|
|
|
|
|
# |
|
153
|
|
|
|
|
|
|
# Main parser method. Scans the input text for Pod sections and splits |
|
154
|
|
|
|
|
|
|
# them into paragraphs. Builds a tree of Pod::POM::Node::* objects |
|
155
|
|
|
|
|
|
|
# to represent the Pod document in object model form. |
|
156
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub parse_text { |
|
159
|
58
|
|
|
58
|
1
|
177330
|
my ($self, $text, $name) = @_; |
|
160
|
58
|
|
|
|
|
95
|
my ($para, $paralen, $gap, $type, $line, $inpod, $code, $result, $verbatim); |
|
161
|
58
|
|
|
|
|
296
|
my $warn = $self->{ WARNINGS } = [ ]; |
|
162
|
|
|
|
|
|
|
|
|
163
|
58
|
|
|
|
|
415
|
my @stack = ( ); |
|
164
|
58
|
|
|
|
|
463
|
my $item = $ROOT->new($self); |
|
165
|
58
|
50
|
|
|
|
172
|
return $self->error($ROOT->error()) |
|
166
|
|
|
|
|
|
|
unless defined $item; |
|
167
|
58
|
|
|
|
|
84
|
push(@stack, $item); |
|
168
|
|
|
|
|
|
|
|
|
169
|
58
|
100
|
|
|
|
149
|
$name = '' unless defined $name; |
|
170
|
58
|
|
|
|
|
310
|
$self->{ FILENAME } = $name; |
|
171
|
|
|
|
|
|
|
|
|
172
|
58
|
|
|
|
|
105
|
$code = $self->{ CODE }; |
|
173
|
58
|
|
|
|
|
109
|
$line = \$self->{ LINE }; |
|
174
|
58
|
|
|
|
|
89
|
$$line = 1; |
|
175
|
58
|
|
|
|
|
76
|
$inpod = 0; |
|
176
|
|
|
|
|
|
|
|
|
177
|
58
|
|
|
|
|
257
|
my @encchunks = split /^(=encoding.*)/m, $text; |
|
178
|
58
|
|
|
|
|
93
|
$text = shift @encchunks; |
|
179
|
58
|
|
|
|
|
168
|
while (@encchunks) { |
|
180
|
2
|
|
|
|
|
6
|
my($encline,$chunk) = splice @encchunks, 0, 2; |
|
181
|
2
|
|
|
|
|
14
|
require Encode; |
|
182
|
2
|
|
|
|
|
11
|
my($encoding) = $encline =~ /^=encoding\s+(\S+)/; |
|
183
|
2
|
100
|
66
|
|
|
18
|
if ($encoding ne 'utf8' || !Encode::is_utf8($chunk)) { |
|
184
|
1
|
|
|
|
|
5
|
Encode::from_to($chunk, $encoding, "utf8"); |
|
185
|
|
|
|
|
|
|
} |
|
186
|
2
|
|
|
|
|
59343
|
Encode::_utf8_on($chunk); |
|
187
|
|
|
|
|
|
|
# $text .= "xxx$encline"; |
|
188
|
2
|
|
|
|
|
15
|
$text .= $chunk; |
|
189
|
|
|
|
|
|
|
} |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
# patch from JJ |
|
192
|
|
|
|
|
|
|
# while ($text =~ /(?:(.*?)(\n{2,}))|(.+$)/sg) { |
|
193
|
58
|
|
|
|
|
607
|
while ($text =~ /(?:(.*?)((?:\s*\n){2,}))|(.+$)/sg) { |
|
194
|
846
|
100
|
|
|
|
3322
|
($para, $gap) = defined $1 ? ($1, $2) : ($3, ''); |
|
195
|
|
|
|
|
|
|
|
|
196
|
846
|
100
|
|
|
|
3372
|
if ($para =~ s/^==?(\w+)\s*//) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
197
|
431
|
|
|
|
|
708
|
$type = $1; |
|
198
|
|
|
|
|
|
|
# switch on for =pod or any other =cmd, switch off for =cut |
|
199
|
431
|
100
|
|
|
|
983
|
if ($type eq 'pod') { $inpod = 1; next } |
|
|
2
|
100
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
3
|
|
|
200
|
13
|
|
|
|
|
21
|
elsif ($type eq 'cut') { $inpod = 0; next } |
|
|
13
|
|
|
|
|
22
|
|
|
201
|
416
|
|
|
|
|
629
|
else { $inpod = 1 }; |
|
202
|
|
|
|
|
|
|
|
|
203
|
416
|
100
|
|
|
|
841
|
if ($type eq 'meta') { |
|
204
|
|
|
|
|
|
|
$self->{ META } |
|
205
|
2
|
50
|
|
|
|
17
|
? $stack[0]->metadata(split(/\s+/, $para, 2)) |
|
206
|
|
|
|
|
|
|
: $self->warning("metadata not allowed", $name, $$line); |
|
207
|
2
|
|
|
|
|
5
|
next; |
|
208
|
|
|
|
|
|
|
} |
|
209
|
|
|
|
|
|
|
} |
|
210
|
|
|
|
|
|
|
elsif (! $inpod) { |
|
211
|
9
|
100
|
|
|
|
22
|
next unless $code; |
|
212
|
4
|
|
|
|
|
6
|
$type = 'code'; |
|
213
|
4
|
|
|
|
|
7
|
$para .= $gap; |
|
214
|
4
|
|
|
|
|
4
|
$gap = ''; |
|
215
|
|
|
|
|
|
|
} |
|
216
|
|
|
|
|
|
|
elsif ($para =~ /^\s+/) { |
|
217
|
39
|
|
|
|
|
73
|
$verbatim .= $para; |
|
218
|
39
|
|
|
|
|
51
|
$verbatim .= $gap; |
|
219
|
39
|
|
|
|
|
56
|
next; |
|
220
|
|
|
|
|
|
|
} |
|
221
|
|
|
|
|
|
|
else { |
|
222
|
367
|
|
|
|
|
451
|
$type = 'text'; |
|
223
|
367
|
|
|
|
|
532
|
chomp($para); # catches last line in file |
|
224
|
|
|
|
|
|
|
} |
|
225
|
|
|
|
|
|
|
|
|
226
|
785
|
100
|
|
|
|
1422
|
if ($verbatim) { |
|
227
|
23
|
|
|
|
|
62
|
while(@stack) { |
|
228
|
38
|
|
|
|
|
180
|
$verbatim =~ s/\s+$//s; |
|
229
|
38
|
|
|
|
|
133
|
$result = $stack[-1]->add($self, 'verbatim', $verbatim); |
|
230
|
|
|
|
|
|
|
|
|
231
|
38
|
50
|
|
|
|
193
|
if (! defined $result) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
232
|
0
|
|
|
|
|
0
|
$self->warning($stack[-1]->error(), $name, $$line); |
|
233
|
0
|
|
|
|
|
0
|
undef $verbatim; |
|
234
|
0
|
|
|
|
|
0
|
last; |
|
235
|
|
|
|
|
|
|
} |
|
236
|
|
|
|
|
|
|
elsif (ref $result) { |
|
237
|
23
|
|
|
|
|
31
|
push(@stack, $result); |
|
238
|
23
|
|
|
|
|
38
|
undef $verbatim; |
|
239
|
23
|
|
|
|
|
33
|
last; |
|
240
|
|
|
|
|
|
|
} |
|
241
|
|
|
|
|
|
|
elsif ($result == REDUCE) { |
|
242
|
0
|
|
|
|
|
0
|
pop @stack; |
|
243
|
0
|
|
|
|
|
0
|
undef $verbatim; |
|
244
|
0
|
|
|
|
|
0
|
last; |
|
245
|
|
|
|
|
|
|
} |
|
246
|
|
|
|
|
|
|
elsif ($result == REJECT) { |
|
247
|
0
|
|
|
|
|
0
|
$self->warning($stack[-1]->error(), $name, $$line); |
|
248
|
0
|
|
|
|
|
0
|
pop @stack; |
|
249
|
|
|
|
|
|
|
} |
|
250
|
|
|
|
|
|
|
elsif (@stack == 1) { |
|
251
|
0
|
|
|
|
|
0
|
$self->warning("unexpected $type", $name, $$line); |
|
252
|
0
|
|
|
|
|
0
|
undef $verbatim; |
|
253
|
0
|
|
|
|
|
0
|
last; |
|
254
|
|
|
|
|
|
|
} |
|
255
|
|
|
|
|
|
|
else { |
|
256
|
15
|
|
|
|
|
37
|
pop @stack; |
|
257
|
|
|
|
|
|
|
} |
|
258
|
|
|
|
|
|
|
} |
|
259
|
|
|
|
|
|
|
} |
|
260
|
|
|
|
|
|
|
|
|
261
|
785
|
|
|
|
|
1521
|
while(@stack) { |
|
262
|
1356
|
|
|
|
|
3822
|
$result = $stack[-1]->add($self, $type, $para); |
|
263
|
|
|
|
|
|
|
|
|
264
|
1356
|
100
|
|
|
|
4217
|
if (! defined $result) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
265
|
3
|
|
|
|
|
8
|
$self->warning($stack[-1]->error(), $name, $$line); |
|
266
|
3
|
|
|
|
|
13
|
last; |
|
267
|
|
|
|
|
|
|
} |
|
268
|
|
|
|
|
|
|
elsif (ref $result) { |
|
269
|
725
|
|
|
|
|
859
|
push(@stack, $result); |
|
270
|
725
|
|
|
|
|
964
|
last; |
|
271
|
|
|
|
|
|
|
} |
|
272
|
|
|
|
|
|
|
elsif ($result == REDUCE) { |
|
273
|
54
|
|
|
|
|
64
|
pop @stack; |
|
274
|
54
|
|
|
|
|
84
|
last; |
|
275
|
|
|
|
|
|
|
} |
|
276
|
|
|
|
|
|
|
elsif ($result == REJECT) { |
|
277
|
3
|
|
|
|
|
8
|
$self->warning($stack[-1]->error(), $name, $$line); |
|
278
|
3
|
|
|
|
|
17
|
pop @stack; |
|
279
|
|
|
|
|
|
|
} |
|
280
|
|
|
|
|
|
|
elsif (@stack == 1) { |
|
281
|
3
|
|
|
|
|
10
|
$self->warning("unexpected $type", $name, $$line); |
|
282
|
3
|
|
|
|
|
13
|
last; |
|
283
|
|
|
|
|
|
|
} |
|
284
|
|
|
|
|
|
|
else { |
|
285
|
568
|
|
|
|
|
1241
|
pop @stack; |
|
286
|
|
|
|
|
|
|
} |
|
287
|
|
|
|
|
|
|
} |
|
288
|
|
|
|
|
|
|
} |
|
289
|
|
|
|
|
|
|
continue { |
|
290
|
846
|
|
|
|
|
1146
|
$$line += ($para =~ tr/\n//); |
|
291
|
846
|
|
|
|
|
7608
|
$$line += ($gap =~ tr/\n//); |
|
292
|
|
|
|
|
|
|
} |
|
293
|
|
|
|
|
|
|
|
|
294
|
58
|
100
|
|
|
|
146
|
if ($verbatim) { |
|
295
|
1
|
|
|
|
|
9
|
while(@stack) { |
|
296
|
1
|
|
|
|
|
5
|
$verbatim =~ s/\s+$//s; |
|
297
|
1
|
|
|
|
|
7
|
$result = $stack[-1]->add($self, 'verbatim', $verbatim); |
|
298
|
|
|
|
|
|
|
|
|
299
|
1
|
50
|
|
|
|
9
|
if (! defined $result) { |
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
300
|
0
|
|
|
|
|
0
|
$self->warning($stack[-1]->error(), $name, $$line); |
|
301
|
0
|
|
|
|
|
0
|
undef $verbatim; |
|
302
|
0
|
|
|
|
|
0
|
last; |
|
303
|
|
|
|
|
|
|
} |
|
304
|
|
|
|
|
|
|
elsif (ref $result) { |
|
305
|
1
|
|
|
|
|
2
|
push(@stack, $result); |
|
306
|
1
|
|
|
|
|
2
|
undef $verbatim; |
|
307
|
1
|
|
|
|
|
2
|
last; |
|
308
|
|
|
|
|
|
|
} |
|
309
|
|
|
|
|
|
|
elsif ($result == REDUCE) { |
|
310
|
0
|
|
|
|
|
0
|
pop @stack; |
|
311
|
0
|
|
|
|
|
0
|
undef $verbatim; |
|
312
|
0
|
|
|
|
|
0
|
last; |
|
313
|
|
|
|
|
|
|
} |
|
314
|
|
|
|
|
|
|
elsif ($result == REJECT) { |
|
315
|
0
|
|
|
|
|
0
|
$self->warning($stack[-1]->error(), $name, $$line); |
|
316
|
0
|
|
|
|
|
0
|
pop @stack; |
|
317
|
|
|
|
|
|
|
} |
|
318
|
|
|
|
|
|
|
elsif (@stack == 1) { |
|
319
|
0
|
|
|
|
|
0
|
$self->warning("unexpected $type", $name, $$line); |
|
320
|
0
|
|
|
|
|
0
|
undef $verbatim; |
|
321
|
0
|
|
|
|
|
0
|
last; |
|
322
|
|
|
|
|
|
|
} |
|
323
|
|
|
|
|
|
|
else { |
|
324
|
0
|
|
|
|
|
0
|
pop @stack; |
|
325
|
|
|
|
|
|
|
} |
|
326
|
|
|
|
|
|
|
} |
|
327
|
|
|
|
|
|
|
} |
|
328
|
|
|
|
|
|
|
|
|
329
|
58
|
|
|
|
|
228
|
return $stack[0]; |
|
330
|
|
|
|
|
|
|
} |
|
331
|
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
334
|
|
|
|
|
|
|
# parse_sequence($text) |
|
335
|
|
|
|
|
|
|
# |
|
336
|
|
|
|
|
|
|
# Parse a text paragraph to identify internal sequences (e.g. B) |
|
337
|
|
|
|
|
|
|
# which may be nested within each other. Returns a simple scalar (no |
|
338
|
|
|
|
|
|
|
# embedded sequences) or a reference to a Pod::POM::Text object. |
|
339
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
340
|
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
sub parse_sequence { |
|
342
|
640
|
|
|
640
|
0
|
926
|
my ($self, $text) = @_; |
|
343
|
640
|
|
|
|
|
638
|
my ($cmd, $lparen, $rparen, $plain); |
|
344
|
640
|
|
|
|
|
1271
|
my ($name, $line, $warn) = @$self{ qw( FILENAME LINE WARNINGS ) }; |
|
345
|
640
|
|
|
|
|
628
|
my @stack; |
|
346
|
|
|
|
|
|
|
|
|
347
|
640
|
|
|
|
|
1760
|
push(@stack, [ '', '', 'EOF', $name, $line, [ ] ] ); |
|
348
|
|
|
|
|
|
|
|
|
349
|
640
|
|
|
|
|
6136
|
while ($text =~ / |
|
350
|
|
|
|
|
|
|
(?: ([A-Z]) (< (?:<+\s)?) ) # open |
|
351
|
|
|
|
|
|
|
| ( (?:\s>+)? > ) # or close |
|
352
|
|
|
|
|
|
|
| (?: (.+?) # or text... |
|
353
|
|
|
|
|
|
|
(?= # ...up to |
|
354
|
|
|
|
|
|
|
(?: [A-Z]< ) # open |
|
355
|
|
|
|
|
|
|
| (?: (?: \s>+)? > ) # or close |
|
356
|
|
|
|
|
|
|
| $ # or EOF |
|
357
|
|
|
|
|
|
|
) |
|
358
|
|
|
|
|
|
|
) |
|
359
|
|
|
|
|
|
|
/gxs) { |
|
360
|
1386
|
100
|
|
|
|
4525
|
if (defined $1) { |
|
|
|
100
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
361
|
192
|
|
|
|
|
384
|
($cmd, $lparen) = ($1, $2); |
|
362
|
192
|
|
|
|
|
402
|
$lparen =~ s/\s$//; |
|
363
|
192
|
|
|
|
|
295
|
($rparen = $lparen) =~ tr/>/; |
|
364
|
192
|
|
|
|
|
1550
|
push(@stack, [ $cmd, $lparen, $rparen, $name, $line, [ ] ]); |
|
365
|
|
|
|
|
|
|
} |
|
366
|
|
|
|
|
|
|
elsif (defined $3) { |
|
367
|
204
|
|
|
|
|
278
|
$rparen = $3; |
|
368
|
204
|
|
|
|
|
362
|
$rparen =~ s/^\s+//; |
|
369
|
204
|
100
|
|
|
|
457
|
if ($rparen eq $stack[-1]->[RPAREN]) { |
|
370
|
189
|
|
50
|
|
|
551
|
$cmd = $TEXTSEQ->new(pop(@stack)) |
|
371
|
|
|
|
|
|
|
|| return $self->error($TEXTSEQ->error()); |
|
372
|
189
|
|
|
|
|
242
|
push(@{ $stack[-1]->[CONTENT] }, $cmd); |
|
|
189
|
|
|
|
|
1230
|
|
|
373
|
|
|
|
|
|
|
} |
|
374
|
|
|
|
|
|
|
else { |
|
375
|
15
|
100
|
|
|
|
91
|
$self->warning((scalar @stack > 1 |
|
376
|
|
|
|
|
|
|
? "expected '$stack[-1]->[RPAREN]' not '$rparen'" |
|
377
|
|
|
|
|
|
|
: "spurious '$rparen'"), $name, $line); |
|
378
|
15
|
|
|
|
|
42
|
push(@{ $stack[-1]->[CONTENT] }, $rparen); |
|
|
15
|
|
|
|
|
127
|
|
|
379
|
|
|
|
|
|
|
} |
|
380
|
|
|
|
|
|
|
} |
|
381
|
|
|
|
|
|
|
elsif (defined $4) { |
|
382
|
990
|
|
|
|
|
1444
|
$plain = $4; |
|
383
|
990
|
|
|
|
|
970
|
push(@{ $stack[-1]->[CONTENT] }, $plain); |
|
|
990
|
|
|
|
|
2136
|
|
|
384
|
990
|
|
|
|
|
3126
|
$line += ($plain =~ tr/\n//); |
|
385
|
|
|
|
|
|
|
} |
|
386
|
|
|
|
|
|
|
else { |
|
387
|
0
|
|
|
|
|
0
|
$self->warning("unexpected end of input", $name, $line); |
|
388
|
0
|
|
|
|
|
0
|
last; |
|
389
|
|
|
|
|
|
|
} |
|
390
|
|
|
|
|
|
|
} |
|
391
|
|
|
|
|
|
|
|
|
392
|
640
|
|
|
|
|
1322
|
while (@stack > 1) { |
|
393
|
3
|
|
|
|
|
5
|
$cmd = pop @stack; |
|
394
|
3
|
|
|
|
|
12
|
$self->warning("unterminated '$cmd->[CMD]$cmd->[LPAREN]' starting", |
|
395
|
|
|
|
|
|
|
$name, $cmd->[LINE]); |
|
396
|
3
|
|
33
|
|
|
16
|
$cmd = $TEXTSEQ->new($cmd) |
|
397
|
|
|
|
|
|
|
|| $self->error($TEXTSEQ->error()); |
|
398
|
3
|
|
|
|
|
4
|
push(@{ $stack[-1]->[CONTENT] }, $cmd); |
|
|
3
|
|
|
|
|
9
|
|
|
399
|
|
|
|
|
|
|
} |
|
400
|
|
|
|
|
|
|
|
|
401
|
640
|
|
33
|
|
|
1930
|
return $TEXTSEQ->new(pop(@stack)) |
|
402
|
|
|
|
|
|
|
|| $self->error($TEXTSEQ->error()); |
|
403
|
|
|
|
|
|
|
} |
|
404
|
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
|
|
406
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
407
|
|
|
|
|
|
|
# default_view($viewer) |
|
408
|
|
|
|
|
|
|
# |
|
409
|
|
|
|
|
|
|
# Accessor method to return or update the $DEFVIEW package variable, |
|
410
|
|
|
|
|
|
|
# loading the module for any package name specified. |
|
411
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
412
|
|
|
|
|
|
|
|
|
413
|
|
|
|
|
|
|
sub default_view { |
|
414
|
1
|
|
|
1
|
0
|
7
|
my ($self, $viewer) = @_; |
|
415
|
1
|
50
|
|
|
|
3
|
return $DEFAULT_VIEW unless $viewer; |
|
416
|
1
|
50
|
|
|
|
4
|
unless (ref $viewer) { |
|
417
|
1
|
|
|
|
|
2
|
my $file = $viewer; |
|
418
|
1
|
|
|
|
|
3
|
$file =~ s[::][/]g; |
|
419
|
1
|
|
|
|
|
2
|
$file .= '.pm'; |
|
420
|
1
|
|
|
|
|
6
|
eval { require $file }; |
|
|
1
|
|
|
|
|
561
|
|
|
421
|
1
|
50
|
|
|
|
12
|
return $self->error($@) if $@; |
|
422
|
|
|
|
|
|
|
} |
|
423
|
|
|
|
|
|
|
|
|
424
|
1
|
|
|
|
|
5
|
return ($DEFAULT_VIEW = $viewer); |
|
425
|
|
|
|
|
|
|
} |
|
426
|
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
|
|
428
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
429
|
|
|
|
|
|
|
# warning($msg, $file, $line) |
|
430
|
|
|
|
|
|
|
# |
|
431
|
|
|
|
|
|
|
# Appends a string of the form " at $file line $line" to $msg if |
|
432
|
|
|
|
|
|
|
# $file is specified and then stores $msg in the internals |
|
433
|
|
|
|
|
|
|
# WARNINGS list. If the WARN option is set then the warning is |
|
434
|
|
|
|
|
|
|
# raised, either via warn(), or by dispatching to a subroutine |
|
435
|
|
|
|
|
|
|
# when WARN is defined as such. |
|
436
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
437
|
|
|
|
|
|
|
|
|
438
|
|
|
|
|
|
|
sub warning { |
|
439
|
27
|
|
|
27
|
0
|
48
|
my ($self, $msg, $file, $line) = @_; |
|
440
|
27
|
|
|
|
|
43
|
my $warn = $self->{ WARN }; |
|
441
|
27
|
50
|
33
|
|
|
131
|
$line = 'unknown' unless defined $line && length $line; |
|
442
|
27
|
50
|
|
|
|
106
|
$msg .= " at $file line $line" if $file; |
|
443
|
|
|
|
|
|
|
|
|
444
|
27
|
|
|
|
|
32
|
push(@{ $self->{ WARNINGS } }, $msg); |
|
|
27
|
|
|
|
|
60
|
|
|
445
|
|
|
|
|
|
|
|
|
446
|
27
|
100
|
|
|
|
102
|
if (ref $warn eq 'CODE') { |
|
|
|
100
|
|
|
|
|
|
|
447
|
6
|
|
|
|
|
13
|
&$warn($msg); |
|
448
|
|
|
|
|
|
|
} |
|
449
|
|
|
|
|
|
|
elsif ($warn) { |
|
450
|
6
|
|
|
|
|
48
|
warn($msg, "\n"); |
|
451
|
|
|
|
|
|
|
} |
|
452
|
|
|
|
|
|
|
} |
|
453
|
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
456
|
|
|
|
|
|
|
# warnings() |
|
457
|
|
|
|
|
|
|
# |
|
458
|
|
|
|
|
|
|
# Returns a reference to the (possibly empty) list of warnings raised by |
|
459
|
|
|
|
|
|
|
# the most recent call to any of the parse_XXX() methods |
|
460
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
461
|
|
|
|
|
|
|
|
|
462
|
|
|
|
|
|
|
sub warnings { |
|
463
|
4
|
|
|
4
|
0
|
17
|
my $self = shift; |
|
464
|
4
|
50
|
|
|
|
11
|
return wantarray ? @{ $self->{ WARNINGS } } : $self->{ WARNINGS }; |
|
|
4
|
|
|
|
|
16
|
|
|
465
|
|
|
|
|
|
|
} |
|
466
|
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
469
|
|
|
|
|
|
|
# error($msg) |
|
470
|
|
|
|
|
|
|
# |
|
471
|
|
|
|
|
|
|
# Sets the internal ERROR member and returns undef when called with an |
|
472
|
|
|
|
|
|
|
# argument(s), returns the current value when called without. |
|
473
|
|
|
|
|
|
|
#------------------------------------------------------------------------ |
|
474
|
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
sub error { |
|
476
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
477
|
0
|
|
|
|
|
|
my $errvar; |
|
478
|
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
{ |
|
480
|
18
|
|
|
18
|
|
46692
|
no strict qw( refs ); |
|
|
18
|
|
|
|
|
46
|
|
|
|
18
|
|
|
|
|
2825
|
|
|
|
0
|
|
|
|
|
|
|
|
481
|
0
|
0
|
|
|
|
|
if (ref $self) { |
|
482
|
0
|
|
|
|
|
|
$errvar = \$self->{ ERROR }; |
|
483
|
|
|
|
|
|
|
} |
|
484
|
|
|
|
|
|
|
else { |
|
485
|
0
|
|
|
|
|
|
$errvar = \${"$self\::ERROR"}; |
|
|
0
|
|
|
|
|
|
|
|
486
|
|
|
|
|
|
|
} |
|
487
|
|
|
|
|
|
|
} |
|
488
|
0
|
0
|
|
|
|
|
if (@_) { |
|
489
|
0
|
0
|
|
|
|
|
$$errvar = ref($_[0]) ? shift : join('', @_); |
|
490
|
0
|
|
|
|
|
|
return undef; |
|
491
|
|
|
|
|
|
|
} |
|
492
|
|
|
|
|
|
|
else { |
|
493
|
0
|
|
|
|
|
|
return $$errvar; |
|
494
|
|
|
|
|
|
|
} |
|
495
|
|
|
|
|
|
|
} |
|
496
|
|
|
|
|
|
|
|
|
497
|
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
|
|
499
|
|
|
|
|
|
|
sub DEBUG { |
|
500
|
0
|
0
|
|
0
|
0
|
|
print STDERR "DEBUG: ", @_ if $DEBUG; |
|
501
|
|
|
|
|
|
|
} |
|
502
|
|
|
|
|
|
|
|
|
503
|
|
|
|
|
|
|
1; |
|
504
|
|
|
|
|
|
|
|
|
505
|
|
|
|
|
|
|
__END__ |