File Coverage

blib/lib/Pod/Abstract/Filter/add_podcmds.pm
Criterion Covered Total %
statement 9 22 40.9
branch 0 6 0.0
condition 0 6 0.0
subroutine 3 4 75.0
pod 1 1 100.0
total 13 39 33.3


line stmt bran cond sub pod time code
1             package Pod::Abstract::Filter::add_podcmds;
2 1     1   1034 use strict;
  1         2  
  1         32  
3              
4 1     1   6 use base qw(Pod::Abstract::Filter);
  1         2  
  1         67  
5 1     1   5 use Pod::Abstract::BuildNode qw(node);
  1         2  
  1         219  
6              
7             our $VERSION = '0.20';
8              
9             =head1 NAME
10              
11             Pod::Abstract::Filter::add_podcmds - paf command to insert explict =pod
12             commands before each Pod block in a document.
13              
14             =head1 METHODS
15              
16             =head2 filter
17              
18             Add a =pod command after each block of cut nodes. This will cause
19             explicit pod declarations wherever they are currently implicit.
20              
21             =cut
22              
23             sub filter {
24 0     0 1   my $self = shift;
25 0           my $pa = shift;
26              
27 0           my @cut_finals = $pa->select(
28             "//#cut[!>>#cut][!>>pod]"
29             );
30              
31             # If the document ends with a cut, we don't want a new Pod section
32             # - but if it ends with a pod, we do.
33 0           my $last_cut = pop @cut_finals;
34 0           my $ignore_last = 1;
35 0           my $p = $last_cut;
36 0 0         $ignore_last = 0 if $p->next;
37 0   0       while($p && ($p = $p->parent) && $ignore_last) {
      0        
38 0 0         $ignore_last = 0 if $p->next;
39             }
40 0 0         push @cut_finals, $last_cut unless $ignore_last;
41              
42 0           foreach my $n (@cut_finals) {
43 0           node->pod->insert_after($n);
44             }
45              
46 0           return $pa;
47             }
48              
49             =head1 AUTHOR
50              
51             Ben Lilburne
52              
53             =head1 COPYRIGHT AND LICENSE
54              
55             Copyright (C) 2009 Ben Lilburne
56              
57             This program is free software; you can redistribute it and/or modify
58             it under the same terms as Perl itself.
59              
60             =cut
61              
62             1;
63