File Coverage

blib/lib/Pod/Elemental.pm
Criterion Covered Total %
statement 36 36 100.0
branch 1 2 50.0
condition n/a
subroutine 11 11 100.0
pod 1 1 100.0
total 49 50 98.0


line stmt bran cond sub pod time code
1             package Pod::Elemental 0.103006;
2             # ABSTRACT: work with nestable Pod elements
3              
4 9     9   630248 use Moose;
  9         3512860  
  9         56  
5              
6 9     9   61188 use namespace::autoclean;
  9         61009  
  9         30  
7              
8 9     9   4083 use Sub::Exporter::ForMethods ();
  9         7824  
  9         365  
9             use Mixin::Linewise::Readers
10 9         59 { installer => Sub::Exporter::ForMethods::method_installer },
11 9     9   1911 -readers;
  9         49258  
12              
13 9     9   8229 use MooseX::Types;
  9         286114  
  9         80  
14              
15 9     9   35129 use Pod::Eventual::Simple 0.004; # nonpod events
  9         8499  
  9         263  
16 9     9   3567 use Pod::Elemental::Document;
  9         31  
  9         610  
17 9     9   5971 use Pod::Elemental::Transformer::Pod5;
  9         33  
  9         306  
18 9     9   3644 use Pod::Elemental::Objectifier;
  9         30  
  9         1914  
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 11     11 1 6595 my ($self, $handle) = @_;
61 11 50       390 $self = $self->new unless ref $self;
62              
63 11         314 my $events = $self->event_reader->read_handle($handle);
64 11         16175 my $elements = $self->objectifier->objectify_events($events);
65              
66 11         369 my $document = $self->document_class->new({
67             children => $elements,
68             });
69              
70 11         360 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 9     9   80 no Moose;
  9         17  
  9         56  
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.103006
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 PERL VERSION
163              
164             This library should run on perls released even a long time ago. It should work
165             on any version of perl released in the last five years.
166              
167             Although it may work on older versions of perl, no guarantee is made that the
168             minimum required version will not be increased. The version may be increased
169             for any reason, and there is no promise that patches will be accepted to lower
170             the minimum required perl.
171              
172             =head1 ATTRIBUTES
173              
174             =head2 event_reader
175              
176             The event reader (by default a new instance of
177             L<Pod::Eventual::Simple|Pod::Eventual::Simple> is used to convert input into an
178             event stream. In general, it should provide C<read_*> methods that behave like
179             Pod::Eventual::Simple.
180              
181             =head2 objectifier
182              
183             The objectifier (by default a new Pod::Elemental::Objectifier) must provide an
184             C<objectify_events> method that converts Pod events into
185             Pod::Elemental::Element objects.
186              
187             =head2 document_class
188              
189             This is the class for documents created by reading pod.
190              
191             =head1 METHODS
192              
193             =head2 read_handle
194              
195             =head2 read_file
196              
197             =head2 read_string
198              
199             These methods read the given input and return a Pod::Elemental::Document.
200              
201             =head1 AUTHOR
202              
203             Ricardo SIGNES <cpan@semiotic.systems>
204              
205             =head1 CONTRIBUTORS
206              
207             =for stopwords Christian Walde Justin Cook Karen Etheridge Philippe Bruhat (BooK) Ricardo Signes
208              
209             =over 4
210              
211             =item *
212              
213             Christian Walde <walde.christian@googlemail.com>
214              
215             =item *
216              
217             Justin Cook <jcook@cray.com>
218              
219             =item *
220              
221             Karen Etheridge <ether@cpan.org>
222              
223             =item *
224              
225             Philippe Bruhat (BooK) <book@cpan.org>
226              
227             =item *
228              
229             Ricardo Signes <rjbs@semiotic.systems>
230              
231             =back
232              
233             =head1 COPYRIGHT AND LICENSE
234              
235             This software is copyright (c) 2022 by Ricardo SIGNES.
236              
237             This is free software; you can redistribute it and/or modify it under
238             the same terms as the Perl 5 programming language system itself.
239              
240             =cut