File Coverage

blib/lib/Pod/Weaver/Section/Leftovers.pm
Criterion Covered Total %
statement 24 24 100.0
branch 2 2 100.0
condition 3 3 100.0
subroutine 5 5 100.0
pod 0 2 0.0
total 34 36 94.4


line stmt bran cond sub pod time code
1             package Pod::Weaver::Section::Leftovers;
2             # ABSTRACT: a place to put everything that nothing else used
3             $Pod::Weaver::Section::Leftovers::VERSION = '4.017';
4 9     9   62451 use Moose;
  9         27  
  9         77  
5             with(
6             'Pod::Weaver::Role::Section',
7             'Pod::Weaver::Role::Finalizer',
8             );
9              
10             #pod =head1 OVERVIEW
11             #pod
12             #pod This section plugin is used to designate where in the output sequence all
13             #pod unused parts of the input C<pod_document> should be placed.
14             #pod
15             #pod Other section plugins are expected to remove from the input Pod document any
16             #pod sections that are consumed. At the end of all section weaving, the Leftovers
17             #pod section will inject any leftover input Pod into its position in the output
18             #pod document.
19             #pod
20             #pod =cut
21              
22 9     9   64120 use Pod::Elemental::Element::Pod5::Region;
  9         24  
  9         379  
23 9     9   62 use Pod::Elemental::Types qw(FormatName);
  9         24  
  9         104  
24              
25             has _marker => (
26             is => 'ro',
27             isa => FormatName,
28             init_arg => undef,
29             default => sub {
30             my ($self) = @_;
31             my $str = sprintf '%s_%s', ref($self), 0+$self;
32             $str =~ s/\W/_/g;
33              
34             return $str;
35             }
36             );
37              
38             sub weave_section {
39 29     29 0 110 my ($self, $document, $input) = @_;
40              
41 29         961 my $placeholder = Pod::Elemental::Element::Pod5::Region->new({
42             is_pod => 0,
43             format_name => $self->_marker,
44             content => '',
45             });
46              
47 29         9111 push @{ $document->children }, $placeholder;
  29         779  
48             }
49              
50             sub finalize_document {
51 27     27 0 104 my ($self, $document, $input) = @_;
52              
53 27         893 my $children = $input->{pod_document}->children;
54 27         868 $input->{pod_document}->children([]);
55              
56 27         943 INDEX: for my $i (0 .. @{ $document->children } - 1) {
  27         790  
57 104         2767 my $para = $document->children->[$i];
58 104 100 100     1989 next unless $para->isa('Pod::Elemental::Element::Pod5::Region')
59             and $para->format_name eq $self->_marker;
60              
61 27         242 $self->log_debug('splicing leftovers back into pod');
62 27         755 splice @{ $document->children }, $i, 1, @$children;
  27         757  
63 27         1106 last INDEX;
64             }
65             }
66              
67             __PACKAGE__->meta->make_immutable;
68             1;
69              
70             __END__
71              
72             =pod
73              
74             =encoding UTF-8
75              
76             =head1 NAME
77              
78             Pod::Weaver::Section::Leftovers - a place to put everything that nothing else used
79              
80             =head1 VERSION
81              
82             version 4.017
83              
84             =head1 OVERVIEW
85              
86             This section plugin is used to designate where in the output sequence all
87             unused parts of the input C<pod_document> should be placed.
88              
89             Other section plugins are expected to remove from the input Pod document any
90             sections that are consumed. At the end of all section weaving, the Leftovers
91             section will inject any leftover input Pod into its position in the output
92             document.
93              
94             =head1 AUTHOR
95              
96             Ricardo SIGNES <rjbs@cpan.org>
97              
98             =head1 COPYRIGHT AND LICENSE
99              
100             This software is copyright (c) 2021 by Ricardo SIGNES.
101              
102             This is free software; you can redistribute it and/or modify it under
103             the same terms as the Perl 5 programming language system itself.
104              
105             =cut