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.020;
2             # ABSTRACT: ensure that the Pod5 translator has been run on this document
3              
4 9     9   6679 use Moose;
  9         28  
  9         83  
5             with 'Pod::Weaver::Role::Preparer';
6              
7             # BEGIN BOILERPLATE
8 9     9   75715 use v5.20.0;
  9         36  
9 9     9   54 use warnings;
  9         22  
  9         614  
10 9     9   84 use utf8;
  9         31  
  9         141  
11 9     9   594 no feature 'switch';
  9         19  
  9         1715  
12 9     9   61 use experimental qw(postderef postderef_qq); # This experiment gets mainlined.
  9         18  
  9         78  
13             # END BOILERPLATE
14              
15 9     9   872 use namespace::autoclean;
  9         22  
  9         111  
16              
17 9     9   931 use Pod::Elemental::Transformer::Pod5;
  9         19  
  9         5384  
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   615 my ($self, $node) = @_;
29              
30             # XXX: This is really stupid. -- rjbs, 2009-10-24
31              
32 53         2065 foreach my $i (reverse 0 .. $node->children->$#*) {
33 337         38901 my $para = $node->children->[$i];
34              
35 337 50       4368 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         6198 $self->_strip_nonpod($para);
43             }
44             }
45             }
46              
47             sub prepare_input {
48 29     29 0 95 my ($self, $input) = @_;
49 29         106 my $pod_document = $input->{pod_document};
50              
51 29         1849 Pod::Elemental::Transformer::Pod5->new->transform_node($pod_document);
52              
53 29         348121 $self->_strip_nonpod($pod_document);
54              
55 29         1582 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.020
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
85             released in the last two to three years. (That is, if the most recently
86             released version is v5.40, then this module should work on both v5.40 and
87             v5.38.)
88              
89             Although it may work on older versions of perl, no guarantee is made that the
90             minimum required version will not be increased. The version may be increased
91             for any reason, and there is no promise that patches will be accepted to
92             lower the minimum required perl.
93              
94             =head1 AUTHOR
95              
96             Ricardo SIGNES <cpan@semiotic.systems>
97              
98             =head1 COPYRIGHT AND LICENSE
99              
100             This software is copyright (c) 2024 by Ricardo SIGNES.
101              
102             This is free software; you can redistribute it and/or modify it under
103             the same terms as the Perl 5 programming language system itself.
104              
105             =cut