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.020;
2             # ABSTRACT: a place to put everything that nothing else used
3              
4 9     9   80252 use Moose;
  9         26  
  9         97  
5             with 'Pod::Weaver::Role::Section',
6             'Pod::Weaver::Role::Finalizer';
7              
8             # BEGIN BOILERPLATE
9 9     9   73860 use v5.20.0;
  9         37  
10 9     9   56 use warnings;
  9         22  
  9         667  
11 9     9   65 use utf8;
  9         18  
  9         126  
12 9     9   455 no feature 'switch';
  9         20  
  9         1742  
13 9     9   87 use experimental qw(postderef postderef_qq); # This experiment gets mainlined.
  9         17  
  9         85  
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   989 use Pod::Elemental::Element::Pod5::Region;
  9         40  
  9         492  
29 9     9   58 use Pod::Elemental::Types qw(FormatName);
  9         18  
  9         172  
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 98 my ($self, $document, $input) = @_;
46              
47 29         1273 my $placeholder = Pod::Elemental::Element::Pod5::Region->new({
48             is_pod => 0,
49             format_name => $self->_marker,
50             content => '',
51             });
52              
53 29         14827 push $document->children->@*, $placeholder;
54             }
55              
56             sub finalize_document {
57 27     27 0 121 my ($self, $document, $input) = @_;
58              
59 27         1269 my $children = $input->{pod_document}->children;
60 27         1126 $input->{pod_document}->children([]);
61              
62 27         1829 INDEX: for my $i (0 .. $document->children->$#*) {
63 104         3612 my $para = $document->children->[$i];
64 104 100 100     2525 next unless $para->isa('Pod::Elemental::Element::Pod5::Region')
65             and $para->format_name eq $self->_marker;
66              
67 27         206 $self->log_debug('splicing leftovers back into pod');
68 27         2124 splice $document->children->@*, $i, 1, @$children;
69 27         1428 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.020
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
101              
102             This module should work on any version of perl still receiving updates from
103             the Perl 5 Porters. This means it should work on any version of perl
104             released in the last two to three years. (That is, if the most recently
105             released version is v5.40, then this module should work on both v5.40 and
106             v5.38.)
107              
108             Although it may work on older versions of perl, no guarantee is made that the
109             minimum required version will not be increased. The version may be increased
110             for any reason, and there is no promise that patches will be accepted to
111             lower the minimum required perl.
112              
113             =head1 AUTHOR
114              
115             Ricardo SIGNES <cpan@semiotic.systems>
116              
117             =head1 COPYRIGHT AND LICENSE
118              
119             This software is copyright (c) 2024 by Ricardo SIGNES.
120              
121             This is free software; you can redistribute it and/or modify it under
122             the same terms as the Perl 5 programming language system itself.
123              
124             =cut