| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Pod::Elemental; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: work with nestable Pod elements |
|
3
|
|
|
|
|
|
|
$Pod::Elemental::VERSION = '0.103004'; |
|
4
|
9
|
|
|
9
|
|
326452
|
use Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use namespace::autoclean; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use Sub::Exporter::ForMethods (); |
|
9
|
|
|
|
|
|
|
use Mixin::Linewise::Readers |
|
10
|
|
|
|
|
|
|
{ installer => Sub::Exporter::ForMethods::method_installer }, |
|
11
|
|
|
|
|
|
|
-readers; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use MooseX::Types; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Pod::Eventual::Simple 0.004; # nonpod events |
|
16
|
|
|
|
|
|
|
use Pod::Elemental::Document; |
|
17
|
|
|
|
|
|
|
use Pod::Elemental::Transformer::Pod5; |
|
18
|
|
|
|
|
|
|
use Pod::Elemental::Objectifier; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
#pod =head1 DESCRIPTION |
|
21
|
|
|
|
|
|
|
#pod |
|
22
|
|
|
|
|
|
|
#pod Pod::Elemental is a system for treating a Pod (L<plain old |
|
23
|
|
|
|
|
|
|
#pod documentation|perlpod>) documents as trees of elements. This model may be |
|
24
|
|
|
|
|
|
|
#pod familiar from many other document systems, especially the HTML DOM. |
|
25
|
|
|
|
|
|
|
#pod Pod::Elemental's document object model is much less sophisticated than the HTML |
|
26
|
|
|
|
|
|
|
#pod DOM, but still makes a lot of document transformations easy. |
|
27
|
|
|
|
|
|
|
#pod |
|
28
|
|
|
|
|
|
|
#pod In general, you'll want to read in a Pod document and then perform a number of |
|
29
|
|
|
|
|
|
|
#pod prepackaged transformations on it. The most common of these will be the L<Pod5 |
|
30
|
|
|
|
|
|
|
#pod transformation|Pod::Elemental::Transformer::Pod5>, which assumes that the basic |
|
31
|
|
|
|
|
|
|
#pod meaning of Pod commands described in the Perl 5 documentation hold: C<=begin>, |
|
32
|
|
|
|
|
|
|
#pod C<=end>, and C<=for> commands mark regions of the document, leading whitespace |
|
33
|
|
|
|
|
|
|
#pod marks a verbatim paragraph, and so on. The Pod5 transformer also eliminates |
|
34
|
|
|
|
|
|
|
#pod the need to track elements representing vertical whitespace. |
|
35
|
|
|
|
|
|
|
#pod |
|
36
|
|
|
|
|
|
|
#pod =head1 SYNOPSIS |
|
37
|
|
|
|
|
|
|
#pod |
|
38
|
|
|
|
|
|
|
#pod use Pod::Elemental; |
|
39
|
|
|
|
|
|
|
#pod use Pod::Elemental::Transformer::Pod5; |
|
40
|
|
|
|
|
|
|
#pod |
|
41
|
|
|
|
|
|
|
#pod my $document = Pod::Elemental->read_file('lib/Pod/Elemental.pm'); |
|
42
|
|
|
|
|
|
|
#pod |
|
43
|
|
|
|
|
|
|
#pod Pod::Elemental::Transformer::Pod5->new->transform_node($document); |
|
44
|
|
|
|
|
|
|
#pod |
|
45
|
|
|
|
|
|
|
#pod print $document->as_debug_string, "\n"; # quick overview of doc structure |
|
46
|
|
|
|
|
|
|
#pod |
|
47
|
|
|
|
|
|
|
#pod print $document->as_pod_string, "\n"; # reproduce the document in Pod |
|
48
|
|
|
|
|
|
|
#pod |
|
49
|
|
|
|
|
|
|
#pod =method read_handle |
|
50
|
|
|
|
|
|
|
#pod |
|
51
|
|
|
|
|
|
|
#pod =method read_file |
|
52
|
|
|
|
|
|
|
#pod |
|
53
|
|
|
|
|
|
|
#pod =method read_string |
|
54
|
|
|
|
|
|
|
#pod |
|
55
|
|
|
|
|
|
|
#pod These methods read the given input and return a Pod::Elemental::Document. |
|
56
|
|
|
|
|
|
|
#pod |
|
57
|
|
|
|
|
|
|
#pod =cut |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub read_handle { |
|
60
|
|
|
|
|
|
|
my ($self, $handle) = @_; |
|
61
|
|
|
|
|
|
|
$self = $self->new unless ref $self; |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $events = $self->event_reader->read_handle($handle); |
|
64
|
|
|
|
|
|
|
my $elements = $self->objectifier->objectify_events($events); |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my $document = $self->document_class->new({ |
|
67
|
|
|
|
|
|
|
children => $elements, |
|
68
|
|
|
|
|
|
|
}); |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
return $document; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
#pod =attr event_reader |
|
74
|
|
|
|
|
|
|
#pod |
|
75
|
|
|
|
|
|
|
#pod The event reader (by default a new instance of |
|
76
|
|
|
|
|
|
|
#pod L<Pod::Eventual::Simple|Pod::Eventual::Simple> is used to convert input into an |
|
77
|
|
|
|
|
|
|
#pod event stream. In general, it should provide C<read_*> methods that behave like |
|
78
|
|
|
|
|
|
|
#pod Pod::Eventual::Simple. |
|
79
|
|
|
|
|
|
|
#pod |
|
80
|
|
|
|
|
|
|
#pod =cut |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
has event_reader => ( |
|
83
|
|
|
|
|
|
|
is => 'ro', |
|
84
|
|
|
|
|
|
|
required => 1, |
|
85
|
|
|
|
|
|
|
default => sub { return Pod::Eventual::Simple->new }, |
|
86
|
|
|
|
|
|
|
); |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
#pod =attr objectifier |
|
89
|
|
|
|
|
|
|
#pod |
|
90
|
|
|
|
|
|
|
#pod The objectifier (by default a new Pod::Elemental::Objectifier) must provide an |
|
91
|
|
|
|
|
|
|
#pod C<objectify_events> method that converts Pod events into |
|
92
|
|
|
|
|
|
|
#pod Pod::Elemental::Element objects. |
|
93
|
|
|
|
|
|
|
#pod |
|
94
|
|
|
|
|
|
|
#pod =cut |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
has objectifier => ( |
|
97
|
|
|
|
|
|
|
is => 'ro', |
|
98
|
|
|
|
|
|
|
isa => duck_type( [qw(objectify_events) ]), |
|
99
|
|
|
|
|
|
|
required => 1, |
|
100
|
|
|
|
|
|
|
default => sub { return Pod::Elemental::Objectifier->new }, |
|
101
|
|
|
|
|
|
|
); |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
#pod =attr document_class |
|
104
|
|
|
|
|
|
|
#pod |
|
105
|
|
|
|
|
|
|
#pod This is the class for documents created by reading pod. |
|
106
|
|
|
|
|
|
|
#pod |
|
107
|
|
|
|
|
|
|
#pod =cut |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
has document_class => ( |
|
110
|
|
|
|
|
|
|
is => 'ro', |
|
111
|
|
|
|
|
|
|
required => 1, |
|
112
|
|
|
|
|
|
|
default => 'Pod::Elemental::Document', |
|
113
|
|
|
|
|
|
|
); |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
116
|
|
|
|
|
|
|
no Moose; |
|
117
|
|
|
|
|
|
|
1; |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
__END__ |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=pod |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=encoding UTF-8 |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 NAME |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Pod::Elemental - work with nestable Pod elements |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 VERSION |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
version 0.103004 |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
use Pod::Elemental; |
|
136
|
|
|
|
|
|
|
use Pod::Elemental::Transformer::Pod5; |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
my $document = Pod::Elemental->read_file('lib/Pod/Elemental.pm'); |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Pod::Elemental::Transformer::Pod5->new->transform_node($document); |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
print $document->as_debug_string, "\n"; # quick overview of doc structure |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
print $document->as_pod_string, "\n"; # reproduce the document in Pod |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Pod::Elemental is a system for treating a Pod (L<plain old |
|
149
|
|
|
|
|
|
|
documentation|perlpod>) documents as trees of elements. This model may be |
|
150
|
|
|
|
|
|
|
familiar from many other document systems, especially the HTML DOM. |
|
151
|
|
|
|
|
|
|
Pod::Elemental's document object model is much less sophisticated than the HTML |
|
152
|
|
|
|
|
|
|
DOM, but still makes a lot of document transformations easy. |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
In general, you'll want to read in a Pod document and then perform a number of |
|
155
|
|
|
|
|
|
|
prepackaged transformations on it. The most common of these will be the L<Pod5 |
|
156
|
|
|
|
|
|
|
transformation|Pod::Elemental::Transformer::Pod5>, which assumes that the basic |
|
157
|
|
|
|
|
|
|
meaning of Pod commands described in the Perl 5 documentation hold: C<=begin>, |
|
158
|
|
|
|
|
|
|
C<=end>, and C<=for> commands mark regions of the document, leading whitespace |
|
159
|
|
|
|
|
|
|
marks a verbatim paragraph, and so on. The Pod5 transformer also eliminates |
|
160
|
|
|
|
|
|
|
the need to track elements representing vertical whitespace. |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head2 event_reader |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
The event reader (by default a new instance of |
|
167
|
|
|
|
|
|
|
L<Pod::Eventual::Simple|Pod::Eventual::Simple> is used to convert input into an |
|
168
|
|
|
|
|
|
|
event stream. In general, it should provide C<read_*> methods that behave like |
|
169
|
|
|
|
|
|
|
Pod::Eventual::Simple. |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 objectifier |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
The objectifier (by default a new Pod::Elemental::Objectifier) must provide an |
|
174
|
|
|
|
|
|
|
C<objectify_events> method that converts Pod events into |
|
175
|
|
|
|
|
|
|
Pod::Elemental::Element objects. |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head2 document_class |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
This is the class for documents created by reading pod. |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 METHODS |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head2 read_handle |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head2 read_file |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head2 read_string |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
These methods read the given input and return a Pod::Elemental::Document. |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 AUTHOR |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Ricardo SIGNES <rjbs@cpan.org> |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
This software is copyright (c) 2014 by Ricardo SIGNES. |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
200
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=cut |