File Coverage

blib/lib/Pod/Abstract/Filter/uncut.pm
Criterion Covered Total %
statement 12 26 46.1
branch 0 2 0.0
condition 0 3 0.0
subroutine 4 5 80.0
pod 1 1 100.0
total 17 37 45.9


line stmt bran cond sub pod time code
1             package Pod::Abstract::Filter::uncut;
2 1     1   992 use strict;
  1         1  
  1         29  
3 1     1   5 use warnings;
  1         1  
  1         24  
4              
5 1     1   4 use base qw(Pod::Abstract::Filter);
  1         2  
  1         113  
6 1     1   5 use Pod::Abstract::BuildNode qw(node);
  1         2  
  1         253  
7              
8             our $VERSION = '0.20';
9              
10             =head1 NAME
11              
12             Pod::Abstract::Filter::uncut - paf command to turn source code into
13             verbatim nodes.
14              
15             =head1 DESCRIPTION
16              
17             Takes all cut blocks from the source document, after the first Pod block
18             starts, and converts them into inline verbatim Pod blocks. The effect of
19             this is to allow viewing of source code inline with the formatted Pod
20             documentation describing it.
21              
22             =cut
23              
24             sub filter {
25 0     0 1   my $self = shift;
26 0           my $pa = shift;
27            
28 0           my @cuts = $pa->select('//#cut[! << #cut]'); # First cut in each run
29            
30 0           foreach my $cut (@cuts) {
31 0 0         next unless $cut->body =~ m/^=cut/;
32 0           my $n = $cut->next;
33 0   0       while( $n && $n->type eq '#cut' ) {
34 0           $cut->push(node->verbatim($n->body));
35 0           $n->detach;
36 0           $n = $cut->next;
37             }
38 0           $cut->coalesce_body(':verbatim');
39 0           $cut->hoist;
40 0           $cut->detach;
41             }
42            
43 0           return $pa;
44             }
45              
46             =head1 AUTHOR
47              
48             Ben Lilburne
49              
50             =head1 COPYRIGHT AND LICENSE
51              
52             Copyright (C) 2009 Ben Lilburne
53              
54             This program is free software; you can redistribute it and/or modify
55             it under the same terms as Perl itself.
56              
57             =cut
58              
59             1;