PAR::Filter::PodStrip - POD-stripping filter


PAR-Packer documentation Contained in the PAR-Packer distribution.

Index


Code Index:

NAME

Top

PAR::Filter::PodStrip - POD-stripping filter

SYNOPSIS

Top

    # transforms $code
    PAR::Filter::PodStrip->apply(\$code, $filename, $name);

DESCRIPTION

Top

This filter strips away all POD sections, but preserves the original file name and line numbers via the #line directive.

SEE ALSO

Top

PAR::Filter

AUTHORS

Top

Audrey Tang <cpan@audreyt.org>

Steffen Mueller <smueller@cpan.org>

http://par.perl.org/ is the official PAR website. You can write to the mailing list at <par@perl.org>, or send an empty mail to <par-subscribe@perl.org> to participate in the discussion.

Please submit bug reports to <bug-par@rt.cpan.org>.

COPYRIGHT

Top


PAR-Packer documentation Contained in the PAR-Packer distribution.
package PAR::Filter::PodStrip;
use 5.006;
use strict;
use warnings;
use base 'PAR::Filter';

sub apply {
    my ($class, $ref, $filename, $name) = @_;

    no warnings 'uninitialized';

    my $data = '';
    $data = $1 if $$ref =~ s/((?:^__DATA__\r?\n).*)//ms;

    my $line = 1;
    if ($$ref =~ /^=(?:head\d|pod|begin|item|over|for|back|end|cut)\b/) {
        $$ref = "\n$$ref";
        $line--;
    }
    $$ref =~ s{(
		(.*?\n)
		(?:=(?:head\d|pod|begin|item|over|for|back|end)\b
        .*?\n)
		(?:=cut[\t ]*[\r\n]*?|\Z)
		(\r?\n)?
        )}{
		my ($pre, $post) = ($2, $3);
                "$pre#line " . (
	    	    $line += ( () = ( $1 =~ /\n/g ) )
		) . $post;
        }gsex;

    $$ref =~ s{^=encoding\s+\S+\s*$}{\n}mg;

    $$ref = '#line 1 "' . ($filename) . "\"\n" . $$ref
        if length $filename;
    $$ref =~ s/^#line 1 (.*\n)(#!.*\n)/$2#line 2 $1/g;
    $$ref .= $data;
}

1;