Elemental.pm

filter: Statementstmt 100% 43 / 43 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 100% 1 / 1 totaltotal 98.3% 58 / 59 CC 2 SCAR 1.3
CC
2
Cov
98%
read_handle
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Elemental/Types.pm ↑ Summary Elemental/Autoblank.pm »
1 package Pod::Elemental 0.103006;
2 # ABSTRACT: work with nestable Pod elements
3  
4 9 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 9 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 9 ▶use Sub::Exporter::ForMethods ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 use Mixin::Linewise::Readers
10 9 ▶ { installer => Sub::Exporter::ForMethods::method_installer },
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 -readers;
12  
13 9 ▶use MooseX::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 9 ▶use Pod::Eventual::Simple 0.004; # nonpod events
Subroutine BEGIN: called CC=1 SCAR=0.0
16 9 ▶use Pod::Elemental::Document;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 9 ▶use Pod::Elemental::Transformer::Pod5;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 9 ▶use Pod::Elemental::Objectifier;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 11 ▶sub read_handle {
Subroutine read_handle: called CC=2 SCAR=7.0
Pod documented
60 11 my ($self, $handle) = @_;
61 11 ▶ $self = $self->new unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 11 0 11
62  
63 11 my $events = $self->event_reader->read_handle($handle);
64 11 my $elements = $self->objectifier->objectify_events($events);
65  
66 11 my $document = $self->document_class->new({
67 children => $elements,
68 });
69  
70 11 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 11 ▶ default => sub { return Pod::Eventual::Simple->new },
Subroutine __ANON__: called CC=1 SCAR=0.0
86 9 );
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 11 ▶ default => sub { return Pod::Elemental::Objectifier->new },
Subroutine __ANON__: called CC=1 SCAR=0.0
101 9 );
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 9 has document_class => (
110 is => 'ro',
111 required => 1,
112 default => 'Pod::Elemental::Document',
113 );
114  
115 9 __PACKAGE__->meta->make_immutable;
116 9 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
117 9 1;
118  
119 __END__
« Elemental/Types.pm ↑ Summary Elemental/Autoblank.pm »