1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
package PAR::Filter::PodStrip;
use 5.006;
use strict;
use warnings;
use base 'PAR::Filter';
=head1 NAME
PAR::Filter::PodStrip - POD-stripping filter
=head1 SYNOPSIS
# transforms $code
PAR::Filter::PodStrip->apply(\$code, $filename, $name);
=head1 DESCRIPTION
This filter strips away all POD sections, but preserves the original
file name and line numbers via the C<#line> directive.
=cut
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;
=head1 SEE ALSO
L<PAR::Filter>
=head1 AUTHORS
Audrey Tang E<lt>cpan@audreyt.orgE<gt>
Steffen Mueller E<lt>smueller@cpan.orgE<gt>
You can write
to the mailing list at E<lt>par@perl.orgE<gt>, or send an empty mail to
E<lt>par-subscribe@perl.orgE<gt> to participate in the discussion.
Archives of the mailing list are available at
E<lt>https://www.mail-archive.com/par@perl.org/E<gt> or E<lt>https://groups.google.com/g/perl.parE<gt>.
Please submit bug reports to E<lt>https://github.com/rschupp/PAR-Packer/issuesE<gt>.
=head1 COPYRIGHT
Copyright 2003-2009 Audrey Tang E<lt>cpan@audreyt.orgE<gt>,
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
See F<LICENSE>.
=cut
|