File Coverage

blib/lib/Pod/Weaver/Plugin/EnsurePod5.pm
Criterion Covered Total %
statement 33 36 91.6
branch 3 6 50.0
condition n/a
subroutine 10 10 100.0
pod 0 1 0.0
total 46 53 86.7


line stmt bran cond sub pod time code
1             package Pod::Weaver::Plugin::EnsurePod5 4.018;
2             # ABSTRACT: ensure that the Pod5 translator has been run on this document
3              
4 9     9   6236 use Moose;
  9         23  
  9         77  
5             with 'Pod::Weaver::Role::Preparer';
6              
7             # BEGIN BOILERPLATE
8 9     9   61767 use v5.20.0;
  9         34  
9 9     9   55 use warnings;
  9         22  
  9         340  
10 9     9   56 use utf8;
  9         22  
  9         85  
11 9     9   361 no feature 'switch';
  9         20  
  9         1188  
12 9     9   83 use experimental qw(postderef postderef_qq); # This experiment gets mainlined.
  9         35  
  9         114  
13             # END BOILERPLATE
14              
15 9     9   1089 use namespace::autoclean;
  9         21  
  9         89  
16              
17 9     9   849 use Pod::Elemental::Transformer::Pod5;
  9         32  
  9         3519  
18              
19             #pod =head1 OVERVIEW
20             #pod
21             #pod This plugin is very, very simple: it runs the Pod5 transformer on the input
22             #pod document and removes any leftover whitespace-only Nonpod elements. If
23             #pod non-whitespace-only Nonpod elements are found, an exception is raised.
24             #pod
25             #pod =cut
26              
27             sub _strip_nonpod {
28 53     53   502 my ($self, $node) = @_;
29              
30             # XXX: This is really stupid. -- rjbs, 2009-10-24
31              
32 53         1487 foreach my $i (reverse 0 .. $node->children->$#*) {
33 337         30630 my $para = $node->children->[$i];
34              
35 337 50       3484 if ($para->isa('Pod::Elemental::Element::Pod5::Nonpod')) {
    100          
36 0 0       0 if ($para->content !~ /\S/) {
37 0         0 splice $node->children->@*, $i, 1
38             } else {
39 0         0 confess "can't cope with a Nonpod element with non-whitespace content";
40             }
41             } elsif ($para->does('Pod::Elemental::Node')) {
42 24         4895 $self->_strip_nonpod($para);
43             }
44             }
45             }
46              
47             sub prepare_input {
48 29     29 0 94 my ($self, $input) = @_;
49 29         77 my $pod_document = $input->{pod_document};
50              
51 29         1255 Pod::Elemental::Transformer::Pod5->new->transform_node($pod_document);
52              
53 29         274867 $self->_strip_nonpod($pod_document);
54              
55 29         1353 return;
56             }
57              
58             __PACKAGE__->meta->make_immutable;
59             1;
60              
61             __END__
62              
63             =pod
64              
65             =encoding UTF-8
66              
67             =head1 NAME
68              
69             Pod::Weaver::Plugin::EnsurePod5 - ensure that the Pod5 translator has been run on this document
70              
71             =head1 VERSION
72              
73             version 4.018
74              
75             =head1 OVERVIEW
76              
77             This plugin is very, very simple: it runs the Pod5 transformer on the input
78             document and removes any leftover whitespace-only Nonpod elements. If
79             non-whitespace-only Nonpod elements are found, an exception is raised.
80              
81             =head1 PERL VERSION SUPPORT
82              
83             This module has the same support period as perl itself: it supports the two
84             most recent versions of perl. (That is, if the most recently released version
85             is v5.40, then this module should work on both v5.40 and v5.38.)
86              
87             Although it may work on older versions of perl, no guarantee is made that the
88             minimum required version will not be increased. The version may be increased
89             for any reason, and there is no promise that patches will be accepted to lower
90             the minimum required perl.
91              
92             =head1 AUTHOR
93              
94             Ricardo SIGNES <rjbs@semiotic.systems>
95              
96             =head1 COPYRIGHT AND LICENSE
97              
98             This software is copyright (c) 2021 by Ricardo SIGNES.
99              
100             This is free software; you can redistribute it and/or modify it under
101             the same terms as the Perl 5 programming language system itself.
102              
103             =cut