summaryrefslogtreecommitdiff
path: root/lib/Pod/Strip.pm
blob: 8a7e84151a899c3665e58c2dbbc4a1a940cdacd9 (plain)
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
87
88
89
90
91
92
93
94
95
package Pod::Strip;

use warnings;
use strict;

use base ('Pod::Simple');

our $VERSION = "1.02";

sub new {
    my $new = shift->SUPER::new(@_);
    $new->{_code_line}=0;
    $new->code_handler(
        sub {
            # Add optional line directives
            if ($_[2]->{_replace_with_comments}) {
                if ($_[2]->{_code_line}+1<$_[1]) {
                    print {$_[2]{output_fh}} ("# stripped POD\n") x ($_[1] - $_[2]->{_code_line} -1 );
                }
                $_[2]->{_code_line}=$_[1];
            }
            print {$_[2]{output_fh}} $_[0],"\n";
            return;
       });
    return $new;
}


sub replace_with_comments {
    my $self = shift;
    $self->{_replace_with_comments} = defined $_[0] ? $_[0] : 1;
}


1;
__END__

=pod

=head1 NAME

Pod::Strip - Remove POD from Perl code

=head1 SYNOPSIS

    use Pod::Strip;

    my $p=Pod::Strip->new;              # create parser
    my $podless;                        # set output string
    $p->output_string(\$podless);       # see Pod::Simple
    $p->parse_string_document($code);   # or some other parsing method
                                        #    from Pod::Simple
    # $podless will now contain code without any POD


=head1 DESCRIPTION

Pod::Strip is a subclass of Pod::Simple that strips all POD from Perl Code.

=head1 METHODS

All methods besides those listed here are inherited from Pod::Simple

=head2 new

Generate a new parser object.

=head2 replace_with_comments

Call this method with a true argument to replace POD with comments (looking like "# stripped POD") instead of stripping it.

This has the effect that line numbers get reported correctly in error
messages etc.

=head1 AUTHOR

Thomas Klausner, C<< <domm@cpan.org> >>

=head1 BUGS

Please report any bugs or feature requests to
C<bug-pod-strip@rt.cpan.org>, or through the web interface at
L<http://rt.cpan.org>.  I will be notified, and then you'll automatically
be notified of progress on your bug as I make changes.

=head1 COPYRIGHT & LICENSE

Copyright 2004, 2005, 2006 Thomas Klausner, All Rights Reserved.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=cut