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;
2             # ABSTRACT: work with nestable Pod elements
3             $Pod::Elemental::VERSION = '0.103005';
4 9     9   730269 use Moose;
  9         4127863  
  9         68  
5              
6 9     9   74339 use namespace::autoclean;
  9         73798  
  9         40  
7              
8 9     9   4668 use Sub::Exporter::ForMethods ();
  9         8483  
  9         374  
9             use Mixin::Linewise::Readers
10 9         61 { installer => Sub::Exporter::ForMethods::method_installer },
11 9     9   2254 -readers;
  9         56248  
12              
13 9     9   9581 use MooseX::Types;
  9         316822  
  9         38  
14              
15 9     9   40165 use Pod::Eventual::Simple 0.004; # nonpod events
  9         9606  
  9         252  
16 9     9   4253 use Pod::Elemental::Document;
  9         33  
  9         392  
17 9     9   5376 use Pod::Elemental::Transformer::Pod5;
  9         38  
  9         374  
18 9     9   4398 use Pod::Elemental::Objectifier;
  9         40  
  9         2273  
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 7701 my ($self, $handle) = @_;
61 11 50       446 $self = $self->new unless ref $self;
62              
63 11         334 my $events = $self->event_reader->read_handle($handle);
64 11         18813 my $elements = $self->objectifier->objectify_events($events);
65              
66 11         375 my $document = $self->document_class->new({
67             children => $elements,
68             });
69              
70 11         344 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   74 no Moose;
  9         21  
  9         478  
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.103005
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 CONTRIBUTORS
196              
197             =for stopwords Christian Walde Justin Cook Karen Etheridge Philippe Bruhat (BooK)
198              
199             =over 4
200              
201             =item *
202              
203             Christian Walde <walde.christian@googlemail.com>
204              
205             =item *
206              
207             Justin Cook <jcook@cray.com>
208              
209             =item *
210              
211             Karen Etheridge <ether@cpan.org>
212              
213             =item *
214              
215             Philippe Bruhat (BooK) <book@cpan.org>
216              
217             =back
218              
219             =head1 COPYRIGHT AND LICENSE
220              
221             This software is copyright (c) 2020 by Ricardo SIGNES.
222              
223             This is free software; you can redistribute it and/or modify it under
224             the same terms as the Perl 5 programming language system itself.
225              
226             =cut