lib/PAR/Filter/PodStrip.pm untested

filter: Statementstmt 0.0% 0 / 27 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 40 CC 4 SCAR 23.0
CC
4
Cov
0%
apply
20.0
BEGIN
2.0
BEGIN
2.0
CRAP 10.0
1 package PAR::Filter::PodStrip;
2 use 5.006;
3 use strict;
4 use warnings;
5 use base 'PAR::Filter';
6  
7 =head1 NAME
8  
9 PAR::Filter::PodStrip - POD-stripping filter
10  
11 =head1 SYNOPSIS
12  
13 # transforms $code
14 PAR::Filter::PodStrip->apply(\$code, $filename, $name);
15  
16 =head1 DESCRIPTION
17  
18 This filter strips away all POD sections, but preserves the original
19 file name and line numbers via the C<#line> directive.
20  
21 =cut
22  
23 sub apply {
24 my ($class, $ref, $filename, $name) = @_;
25  
26 no warnings 'uninitialized';
27  
28 my $data = '';
29 $data = $1 if $$ref =~ s/((?:^__DATA__\r?\n).*)//ms;
30  
31 my $line = 1;
32 if ($$ref =~ /^=(?:head\d|pod|begin|item|over|for|back|end|cut)\b/) {
33 $$ref = "\n$$ref";
34 $line--;
35 }
36 $$ref =~ s{(
37 (.*?\n)
38 (?:=(?:head\d|pod|begin|item|over|for|back|end)\b
39 .*?\n)
40 (?:=cut[\t ]*[\r\n]*?|\Z)
41 (\r?\n)?
42 )}{
43 my ($pre, $post) = ($2, $3);
44 "$pre#line " . (
45 $line += ( () = ( $1 =~ /\n/g ) )
46 ) . $post;
47 }gsex;
48  
49 $$ref =~ s{^=encoding\s+\S+\s*$}{\n}mg;
50  
51 $$ref = '#line 1 "' . ($filename) . "\"\n" . $$ref
52 if length $filename;
53 $$ref =~ s/^#line 1 (.*\n)(#!.*\n)/$2#line 2 $1/g;
54 $$ref .= $data;
55 }
56  
57 1;
58  
59 =head1 SEE ALSO
60  
61 L<PAR::Filter>
62  
63 =head1 AUTHORS
64  
65 Audrey Tang E<lt>cpan@audreyt.orgE<gt>
66  
67 Steffen Mueller E<lt>smueller@cpan.orgE<gt>
68  
69 You can write
70 to the mailing list at E<lt>par@perl.orgE<gt>, or send an empty mail to
71 E<lt>par-subscribe@perl.orgE<gt> to participate in the discussion.
72 Archives of the mailing list are available at
73 E<lt>https://www.mail-archive.com/par@perl.org/E<gt> or E<lt>https://groups.google.com/g/perl.parE<gt>.
74  
75 Please submit bug reports to E<lt>https://github.com/rschupp/PAR-Packer/issuesE<gt>.
76  
77 =head1 COPYRIGHT
78  
79 Copyright 2003-2009 Audrey Tang E<lt>cpan@audreyt.orgE<gt>,
80  
81 This program is free software; you can redistribute it and/or modify it
82 under the same terms as Perl itself.
83  
84 See F<LICENSE>.
85  
86 =cut