File Coverage

blib/lib/Pod/Simpler/Aoh.pm
Criterion Covered Total %
statement 41 44 93.1
branch 24 30 80.0
condition 8 10 80.0
subroutine 12 12 100.0
pod 3 3 100.0
total 88 99 88.8


line stmt bran cond sub pod time code
1             package Pod::Simpler::Aoh;
2              
3 6     6   754620 use Moo;
  6         56808  
  6         41  
4 6     6   13926 use MooX::LazierAttributes;
  6         174435  
  6         41  
5 6     6   6423 use Types::Standard qw/Str ArrayRef HashRef Bool/;
  6         1072843  
  6         83  
6              
7             extends 'Pod::Simple';
8              
9             our $VERSION = '1.00';
10              
11             attributes(
12             pod => [ rw, ArrayRef, { lzy_array, clr } ],
13             section => [ rw, HashRef, { lzy_hash, clr } ],
14             pod_elements => [ HashRef, { lzy, bld } ],
15             element_name => [ rw, Str, { clr } ],
16             split_content => [ rw, Bool, { clr } ]
17             );
18              
19             sub _build_pod_elements {
20             return {
21 9     9   475 Document => 'skip',
22             head1 => 'title',
23             head2 => 'title',
24             head2 => 'title',
25             head4 => 'title',
26             Para => 'content',
27             'item-text' => 'content',
28             'over-text' => 'content',
29             'over-bullet' => 'content',
30             'item-bullet' => 'content',
31             Verbatim => 'content',
32             Data => 'content',
33             C => 'content',
34             L => 'content',
35             B => 'content',
36             I => 'content',
37             E => 'content',
38             F => 'content',
39             S => 'content',
40             X => 'content',
41             join => 'content',
42             };
43             }
44              
45             for (qw/parse_file parse_from_file parse_string_document/) {
46             around $_ => sub {
47             my ( $orig, $self, $args ) = @_;
48             $self->clear_pod;
49             $self->$orig($args);
50             return $self->pod;
51             };
52             }
53              
54             sub find {
55 1     1 1 33 my @sections;
56 1         7 for ($_[0]->aoh) {
57 35 100       123 push @sections, $_ if $_->{$_[1]} =~ m/$_[2]/i;
58             }
59 1 50       7 return wantarray ? @sections : $sections[0];
60             }
61              
62             sub get {
63 8     8 1 341 return $_[0]->pod->[ $_[1] ];
64             }
65              
66             sub aoh {
67 1     1 1 2 return @{ $_[0]->pod };
  1         29  
68             }
69              
70             sub _handle_element_start {
71 1259     1259   439745 $_[0]->element_name( $_[1] );
72 1259 100       58777 if ( $_[0]->pod_elements->{ $_[1] } eq 'title' ) {
73             $_[0]->section->{title} && $_[0]->section->{identifier}
74 169 50 66     52957 and $_[0]->_insert_pod;
75             not $_[0]->section->{identifier}
76 169 50       3831 and $_[0]->section->{identifier} = $_[1];
77             }
78             }
79              
80             sub _handle_text {
81 1499   100 1499   57844 my $el_name = $_[0]->element_name || 'join';
82 1499         31956 $_[0]->clear_element_name;
83 1499         28723 my $pel = $_[0]->pod_elements->{$el_name};
84 1499 100       12443 if ($pel =~ m#content#) {
    50          
85 1330         3935 my $el_args = {
86             text => $_[1],
87             element_name => $el_name,
88             };
89 1330 50       22111 if ($_[0]->split_content) {
90 0         0 $el_args->{content} = delete $el_args->{text};
91 0         0 push @{$_[0]->section->{content}}, $el_args;
  0         0  
92             } else {
93 1330         28623 $el_args->{content} = $_[0]->section->{content};
94             $_[0]->section->{content} =
95 1330         9951 $_[0]->_parse_text( 'content', $el_args );
96             }
97             }
98             elsif ($pel =~ m!title!) {
99 169         2660 $_[0]->section->{title} = $_[1];
100             }
101             }
102              
103             sub _handle_element_end {
104 1259 100   1259   20503 if ( $_[0]->source_dead ) {
105             $_[0]->_insert_pod
106             if $_[0]->section->{title}
107 18 50 66     452 && $_[0]->section->{identifier};
108             }
109             }
110              
111             sub _insert_pod {
112 169     169   5069 push @{ $_[0]->pod }, $_[0]->section;
  169         3060  
113 169         8649 return $_[0]->clear_section;
114             }
115              
116             sub _parse_text {
117 1330   100 1330   4848 my $content = $_[2]->{$_[1]} || '';
118 1330 100       6159 if ( $_[2]->{element_name} =~ m{item-text|over-text} ) {
    100          
    100          
119 117         2726 return sprintf "%s\n\n%s\n\n", $content, $_[2]->{text};
120             }
121             # expecting a code example
122             elsif ( $_[2]->{element_name} =~ m/Verbatim/ ) {
123 77 100       1817 return $content ? sprintf "%s\n\n%s\n\n", $content, $_[2]->{text} : sprintf("%s\n\n", $_[2]->{text});
124             }
125             elsif ( $content =~ /[\;\.\:\*]$/ ) {
126 205         4948 return sprintf "%s\n\n%s", $content, $_[2]->{text};
127             }
128 931 100       22387 return $content ? sprintf "%s%s", $content, $_[2]->{text} : $_[2]->{text};
129             }
130              
131              
132             1;
133              
134             __END__