File Coverage

blib/lib/Pod/Abstract/Filter/uncut.pm
Criterion Covered Total %
statement 12 30 40.0
branch 0 2 0.0
condition 0 3 0.0
subroutine 4 5 80.0
pod 1 1 100.0
total 17 41 41.4


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