File Coverage

blib/lib/Pod/Weaver/Section/Leftovers.pm
Criterion Covered Total %
statement 35 35 100.0
branch 2 2 100.0
condition 3 3 100.0
subroutine 10 10 100.0
pod 0 2 0.0
total 50 52 96.1


line stmt bran cond sub pod time code
1             package Pod::Weaver::Section::Leftovers 4.018;
2             # ABSTRACT: a place to put everything that nothing else used
3              
4 9     9   58341 use Moose;
  9         25  
  9         202  
5             with 'Pod::Weaver::Role::Section',
6             'Pod::Weaver::Role::Finalizer';
7              
8             # BEGIN BOILERPLATE
9 9     9   61460 use v5.20.0;
  9         32  
10 9     9   62 use warnings;
  9         21  
  9         325  
11 9     9   57 use utf8;
  9         22  
  9         85  
12 9     9   379 no feature 'switch';
  9         124  
  9         1088  
13 9     9   99 use experimental qw(postderef postderef_qq); # This experiment gets mainlined.
  9         21  
  9         151  
14             # END BOILERPLATE
15              
16             #pod =head1 OVERVIEW
17             #pod
18             #pod This section plugin is used to designate where in the output sequence all
19             #pod unused parts of the input C<pod_document> should be placed.
20             #pod
21             #pod Other section plugins are expected to remove from the input Pod document any
22             #pod sections that are consumed. At the end of all section weaving, the Leftovers
23             #pod section will inject any leftover input Pod into its position in the output
24             #pod document.
25             #pod
26             #pod =cut
27              
28 9     9   1178 use Pod::Elemental::Element::Pod5::Region;
  9         29  
  9         327  
29 9     9   54 use Pod::Elemental::Types qw(FormatName);
  9         38  
  9         101  
30              
31             has _marker => (
32             is => 'ro',
33             isa => FormatName,
34             init_arg => undef,
35             default => sub {
36             my ($self) = @_;
37             my $str = sprintf '%s_%s', ref($self), 0+$self;
38             $str =~ s/\W/_/g;
39              
40             return $str;
41             }
42             );
43              
44             sub weave_section {
45 29     29 0 99 my ($self, $document, $input) = @_;
46              
47 29         947 my $placeholder = Pod::Elemental::Element::Pod5::Region->new({
48             is_pod => 0,
49             format_name => $self->_marker,
50             content => '',
51             });
52              
53 29         9707 push $document->children->@*, $placeholder;
54             }
55              
56             sub finalize_document {
57 27     27 0 94 my ($self, $document, $input) = @_;
58              
59 27         821 my $children = $input->{pod_document}->children;
60 27         870 $input->{pod_document}->children([]);
61              
62 27         1537 INDEX: for my $i (0 .. $document->children->$#*) {
63 104         2683 my $para = $document->children->[$i];
64 104 100 100     1896 next unless $para->isa('Pod::Elemental::Element::Pod5::Region')
65             and $para->format_name eq $self->_marker;
66              
67 27         188 $self->log_debug('splicing leftovers back into pod');
68 27         1471 splice $document->children->@*, $i, 1, @$children;
69 27         1160 last INDEX;
70             }
71             }
72              
73             __PACKAGE__->meta->make_immutable;
74             1;
75              
76             __END__
77              
78             =pod
79              
80             =encoding UTF-8
81              
82             =head1 NAME
83              
84             Pod::Weaver::Section::Leftovers - a place to put everything that nothing else used
85              
86             =head1 VERSION
87              
88             version 4.018
89              
90             =head1 OVERVIEW
91              
92             This section plugin is used to designate where in the output sequence all
93             unused parts of the input C<pod_document> should be placed.
94              
95             Other section plugins are expected to remove from the input Pod document any
96             sections that are consumed. At the end of all section weaving, the Leftovers
97             section will inject any leftover input Pod into its position in the output
98             document.
99              
100             =head1 PERL VERSION SUPPORT
101              
102             This module has the same support period as perl itself: it supports the two
103             most recent versions of perl. (That is, if the most recently released version
104             is v5.40, then this module should work on both v5.40 and v5.38.)
105              
106             Although it may work on older versions of perl, no guarantee is made that the
107             minimum required version will not be increased. The version may be increased
108             for any reason, and there is no promise that patches will be accepted to lower
109             the minimum required perl.
110              
111             =head1 AUTHOR
112              
113             Ricardo SIGNES <rjbs@semiotic.systems>
114              
115             =head1 COPYRIGHT AND LICENSE
116              
117             This software is copyright (c) 2021 by Ricardo SIGNES.
118              
119             This is free software; you can redistribute it and/or modify it under
120             the same terms as the Perl 5 programming language system itself.
121              
122             =cut