Pod::Abstract::Filter::uncut - paf command to turn source code into


Pod-Abstract documentation Contained in the Pod-Abstract distribution.

Index


Code Index:

NAME

Top

Pod::Abstract::Filter::uncut - paf command to turn source code into verbatim nodes.

DESCRIPTION

Top

Takes all cut blocks from the source document, after the first Pod block starts, and converts them into inline verbatim Pod blocks. The effect of this is to allow viewing of source code inline with the formatted Pod documentation describing it.

AUTHOR

Top

Ben Lilburne <bnej@mac.com>

COPYRIGHT AND LICENSE

Top


Pod-Abstract documentation Contained in the Pod-Abstract distribution.
package Pod::Abstract::Filter::uncut;
use strict;
use warnings;

use base qw(Pod::Abstract::Filter);
use Pod::Abstract::BuildNode qw(node);

our $VERSION = '0.20';

sub filter {
    my $self = shift;
    my $pa = shift;
    
    my @cuts = $pa->select('//#cut[! << #cut]'); # First cut in each run
    
    foreach my $cut (@cuts) {
        next unless $cut->body =~ m/^=cut/;
        my $n = $cut->next;
        while( $n && $n->type eq '#cut' ) {
            $cut->push(node->verbatim($n->body));
            $n->detach;
            $n = $cut->next;
        }
        $cut->coalesce_body(':verbatim');
        $cut->hoist;
        $cut->detach;
    }
    
    return $pa;
}

1;