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.019;
2             # ABSTRACT: ensure that the Pod5 translator has been run on this document
3              
4 9     9   6085 use Moose;
  9         23  
  9         80  
5             with 'Pod::Weaver::Role::Preparer';
6              
7             # BEGIN BOILERPLATE
8 9     9   64406 use v5.20.0;
  9         33  
9 9     9   66 use warnings;
  9         21  
  9         347  
10 9     9   69 use utf8;
  9         29  
  9         85  
11 9     9   368 no feature 'switch';
  9         22  
  9         1136  
12 9     9   70 use experimental qw(postderef postderef_qq); # This experiment gets mainlined.
  9         21  
  9         105  
13             # END BOILERPLATE
14              
15 9     9   1127 use namespace::autoclean;
  9         22  
  9         105  
16              
17 9     9   845 use Pod::Elemental::Transformer::Pod5;
  9         20  
  9         3748  
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   575 my ($self, $node) = @_;
29              
30             # XXX: This is really stupid. -- rjbs, 2009-10-24
31              
32 53         1503 foreach my $i (reverse 0 .. $node->children->$#*) {
33 337         31327 my $para = $node->children->[$i];
34              
35 337 50       3540 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         4980 $self->_strip_nonpod($para);
43             }
44             }
45             }
46              
47             sub prepare_input {
48 29     29 0 120 my ($self, $input) = @_;
49 29         88 my $pod_document = $input->{pod_document};
50              
51 29         1293 Pod::Elemental::Transformer::Pod5->new->transform_node($pod_document);
52              
53 29         285021 $self->_strip_nonpod($pod_document);
54              
55 29         1428 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.019
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
82              
83             This module should work on any version of perl still receiving updates from
84             the Perl 5 Porters. This means it should work on any version of perl released
85             in the last two to three years. (That is, if the most recently released
86             version is v5.40, then this module should work on both v5.40 and v5.38.)
87              
88             Although it may work on older versions of perl, no guarantee is made that the
89             minimum required version will not be increased. The version may be increased
90             for any reason, and there is no promise that patches will be accepted to lower
91             the minimum required perl.
92              
93             =head1 AUTHOR
94              
95             Ricardo SIGNES <cpan@semiotic.systems>
96              
97             =head1 COPYRIGHT AND LICENSE
98              
99             This software is copyright (c) 2023 by Ricardo SIGNES.
100              
101             This is free software; you can redistribute it and/or modify it under
102             the same terms as the Perl 5 programming language system itself.
103              
104             =cut