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.019;
2             # ABSTRACT: a place to put everything that nothing else used
3              
4 9     9   61263 use Moose;
  9         31  
  9         209  
5             with 'Pod::Weaver::Role::Section',
6             'Pod::Weaver::Role::Finalizer';
7              
8             # BEGIN BOILERPLATE
9 9     9   65047 use v5.20.0;
  9         36  
10 9     9   67 use warnings;
  9         24  
  9         374  
11 9     9   75 use utf8;
  9         31  
  9         99  
12 9     9   350 no feature 'switch';
  9         133  
  9         1221  
13 9     9   79 use experimental qw(postderef postderef_qq); # This experiment gets mainlined.
  9         19  
  9         186  
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   1148 use Pod::Elemental::Element::Pod5::Region;
  9         25  
  9         434  
29 9     9   71 use Pod::Elemental::Types qw(FormatName);
  9         28  
  9         145  
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 109 my ($self, $document, $input) = @_;
46              
47 29         925 my $placeholder = Pod::Elemental::Element::Pod5::Region->new({
48             is_pod => 0,
49             format_name => $self->_marker,
50             content => '',
51             });
52              
53 29         10144 push $document->children->@*, $placeholder;
54             }
55              
56             sub finalize_document {
57 27     27 0 114 my ($self, $document, $input) = @_;
58              
59 27         851 my $children = $input->{pod_document}->children;
60 27         923 $input->{pod_document}->children([]);
61              
62 27         1653 INDEX: for my $i (0 .. $document->children->$#*) {
63 104         2844 my $para = $document->children->[$i];
64 104 100 100     1997 next unless $para->isa('Pod::Elemental::Element::Pod5::Region')
65             and $para->format_name eq $self->_marker;
66              
67 27         281 $self->log_debug('splicing leftovers back into pod');
68 27         1848 splice $document->children->@*, $i, 1, @$children;
69 27         1125 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.019
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 released
104             in the last two to three years. (That is, if the most recently released
105             version is v5.40, then this module should work on both v5.40 and v5.38.)
106              
107             Although it may work on older versions of perl, no guarantee is made that the
108             minimum required version will not be increased. The version may be increased
109             for any reason, and there is no promise that patches will be accepted to lower
110             the minimum required perl.
111              
112             =head1 AUTHOR
113              
114             Ricardo SIGNES <cpan@semiotic.systems>
115              
116             =head1 COPYRIGHT AND LICENSE
117              
118             This software is copyright (c) 2023 by Ricardo SIGNES.
119              
120             This is free software; you can redistribute it and/or modify it under
121             the same terms as the Perl 5 programming language system itself.
122              
123             =cut