File Coverage

blib/lib/Pod/Elemental/Document.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package Pod::Elemental::Document;
2             # ABSTRACT: a pod document
3             $Pod::Elemental::Document::VERSION = '0.103004';
4 1     1   16976 use Moose;
  0            
  0            
5             with 'Pod::Elemental::Node';
6              
7             use Class::Load ();
8             use namespace::autoclean;
9              
10             use Pod::Elemental::Element::Generic::Blank;
11             use String::RewritePrefix;
12              
13             #pod =head1 OVERVIEW
14             #pod
15             #pod Pod::Elemental::Document is a container for Pod documents. It performs
16             #pod L<Pod::Elemental::Node> but I<not> L<Pod::Elemental::Paragraph>.
17             #pod
18             #pod Documents are used almost exclusively to give a small amount of behavior to
19             #pod arrayrefs of paragraphs, and have few methods of their own.
20             #pod
21             #pod =cut
22              
23             sub _expand_name {
24             my ($self, $name) = @_;
25              
26             return String::RewritePrefix->rewrite(
27             {
28             '' => 'Pod::Elemental::Element::',
29             '=' => ''
30             },
31             $name,
32             );
33             }
34              
35             sub as_pod_string {
36             my ($self) = @_;
37              
38             my $str = join q{}, map { $_->as_pod_string } @{ $self->children };
39              
40             $str = "=pod\n\n$str" unless $str =~ /\A=pod\n/;
41             $str .= "=cut\n" unless $str =~ /=cut\n+\z/;
42              
43             return $str;
44             }
45              
46             sub as_debug_string {
47             return 'Document'
48             }
49              
50             sub _elem_from_lol_entry {
51             my ($self, $entry) = @_;
52             my ($type, $content, $arg) = @$entry;
53             $arg ||= {};
54              
55             if (! defined $type) {
56             my $n_class = $self->_expand_name($arg->{class} || 'Generic::Text');
57             Class::Load::load_class($n_class);
58             return $n_class->new({ content => "$content\n" });
59             } elsif ($type =~ /\A=(\w+)\z/) {
60             my $command = $1;
61             my $n_class = $self->_expand_name($arg->{class} || 'Generic::Command');
62             Class::Load::load_class($n_class);
63             return $n_class->new({
64             command => $command,
65             content => "$content\n"
66             });
67             } else {
68             my $n_class = $self->_expand_name($arg->{class} || 'Pod5::Region');
69             Class::Load::load_class($n_class);
70              
71             my @children;
72              
73             for my $child (@$content) {
74             push @children, $self->_elem_from_lol_entry($child);
75             } continue {
76             my $blank = $self->_expand_name('Generic::Blank');
77             push @children, $blank->new({ content => "\n" });
78             }
79              
80             pop @children
81             while $children[-1]->isa('Pod::Elemental::Element::Generic::Blank');
82              
83             my ($colon, $target) = $type =~ /\A(:)?(.+)\z/;
84              
85             return $n_class->new({
86             format_name => $target,
87             is_pod => $colon ? 1 : 0,
88             content => "\n",
89             children => \@children,
90             })
91             }
92             }
93              
94             sub new_from_lol {
95             my ($class, $lol) = @_;
96              
97             my $self = $class->new;
98              
99             my @children;
100             ENTRY: for my $entry (@$lol) {
101             my $elem = $self->_elem_from_lol_entry($entry);
102             push @children, $elem;
103             } continue {
104             my $blank = $self->_expand_name('Generic::Blank');
105             push @children, $blank->new({ content => "\n" });
106             }
107              
108             push @{ $self->children }, @children;
109              
110             return $self;
111             }
112              
113             __PACKAGE__->meta->make_immutable;
114              
115             1;
116              
117             __END__
118              
119             =pod
120              
121             =encoding UTF-8
122              
123             =head1 NAME
124              
125             Pod::Elemental::Document - a pod document
126              
127             =head1 VERSION
128              
129             version 0.103004
130              
131             =head1 OVERVIEW
132              
133             Pod::Elemental::Document is a container for Pod documents. It performs
134             L<Pod::Elemental::Node> but I<not> L<Pod::Elemental::Paragraph>.
135              
136             Documents are used almost exclusively to give a small amount of behavior to
137             arrayrefs of paragraphs, and have few methods of their own.
138              
139             =head1 AUTHOR
140              
141             Ricardo SIGNES <rjbs@cpan.org>
142              
143             =head1 COPYRIGHT AND LICENSE
144              
145             This software is copyright (c) 2014 by Ricardo SIGNES.
146              
147             This is free software; you can redistribute it and/or modify it under
148             the same terms as the Perl 5 programming language system itself.
149              
150             =cut