Pod::Stripper - strip all pod, and output what's left


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

Index


Code Index:

NAME

Top

Pod::Stripper - strip all pod, and output what's left

SYNOPSIS

Top

    $>perl Stripper.pm

or

    #!/usr/bin/perl -w

    use strict;
    use Pod::Stripper;

    my $Stripper = new Pod::Stripper();

    $Stripper->parse_from_filehandle(\*STDIN) unless (@ARGV);

    for my $ARGV (@ARGV) {
        $Stripper->parse_from_file($ARGV);
    }

DESCRIPTION

Top

This be Pod::Stripper, a subclass of Pod::Parser. It parses perl files, stripping out the pod, and dumping the rest (presumably code) to wherever you point it to (like you do with Pod::Parser).

You could probably subclass it, but I don't see why.

MOTIVATION

I basically re-wrote Pod::Stripper on two separate occasions, and I know at least 2 other people who'd use it, and thought It'd make a nice addition.

perl -MPod::Stripper -e"Pod::Stripper->new()->parse_from_file(shift)" Stripper.pm

EXPORTS

None. This one be object oriented (at least I'm under the impression that it is).

SEE ALSO

Pod::Parser and Pod::Parser, esp. the input_* and output_* methods

CAVEAT

Top

This module will correctly strip out get rid of hidden pod, and preserve hiddencode, but like all pod parsers except perl, it will be fooled by pod in heredocs (or things like that).

see perlpod and read Stripper.pm for more information.

AUTHOR

Top

D.H. aka crazyinsomniac|at|yahoo.com.

LICENSE

Top

Copyright (c) 2002 by D.H. aka crazyinsomniac|at|yahoo.com. All rights reserved.

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

PROPS

Top

props to all the perlmonks at perlmonks.org, and especiall danger and the ones who showed interest in Pod::Stripper

http://perlmonks.org/index.pl?node=Pod::Stripper

The Following is more interesting if you read Stripper.pm raw

Top

TEST CASE FOLLOWS - NOT POD NOR CODE

Top

HEY THIS POD TOO (REALLy, == is valid, although some parsers might disagree)

podchecker will not complain

ABTEST print "THIS IS HIDDEN POD"; =cut

CUT

had to make sure

WELL IF THIS WASN'T AFTER __END__ "this would still be hidden pod"; =cut

THIS REALLY IS AN UGLY HACK

yes, it is


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

package Pod::Stripper; # this one is a little more stylish (see perlstyle)
use strict;
use Pod::Parser;
local $^W = 1; # flip on teh warnings

use vars qw/ @ISA $VERSION/;

$VERSION = 0.22;

@ISA = qw(Pod::Parser); # Pod'Parser is also legal

sub begin_input {
    my ($Stripper) = @_;

## SUPER cause I override parseopts, so the user can't mess w/it
    $Stripper->SUPER::parseopts('-want_nonPODs'    => 1,
                                '-process_cut_cmd' => 9,

                              ,);

    $Stripper->{__2hidden_code}=0;
    return undef;
}

sub cutting {
   my ($Stripper, $cutting) = @_;

   $Stripper->{_CUTTING} = $cutting  if defined $cutting;

   return $$Stripper{_CUTTING};
}

sub begin_pod {
    my ($Stripper) = @_;

    $Stripper->cutting(1);

    return undef;
}

sub end_pod {
    my ($Stripper) = @_;

    $Stripper->cutting(0);

    return;
}

sub preprocess_paragraph
{
    my ($Stripper, $text) = @_;

    if( $Stripper->cutting() ) {
        my $out_fh = $Stripper->output_handle();
        print $out_fh $text;
        return undef;
    }
    else {
        return $text;
    }
}

sub command
{
    my ($Stripper, $command, $paragraph, $line_num, $pod_para) = @_;

    if($paragraph =~ m/^=cut/mg) {
        $Stripper->{__2hidden_code} = 1 ;
        ## it's hidden code (the unseen =cut command)
    }


    if ($command eq 'cut') {
        $Stripper->cutting(1);
        ## it's non-pod now
    }
    else {
        $Stripper->cutting(0);
        ## it's pod now
    }
}

sub verbatim { &textblock(@_); } ## cause hidden code can be either

sub textblock {
    my ($Stripper, $paragraph, $line_num, $pod_para) = @_;

## guess what we got? that's right, hidden code
    if($Stripper->{__2hidden_code}) {
        $Stripper->{__2hidden_code} = 0;
        my $out_fh = $Stripper->output_handle();
        print $out_fh $paragraph;
    }

}
    

sub parseopts {undef}

1;
################################################################################
################################################################################

package main;

unless(caller()) {
    my $Stripper = new Pod::Stripper();
    
    seek DATA,0,0;
    
    $Stripper->parse_from_filehandle(\*DATA);

print ">>>>>>>>>>>>>>> I AM NOT HIDDEN POD.  PERL WILL EXECUTE ME";

my $BUT_BEFORE_THE_MODULE_ENDS = <<'A_TEST';

=head2 I AM INSIDE A HEREDOC

WHERE ARE YOU?

=cut

=head2 I AM HIDDEN POD INSIDE A HEREDOC
warn "really, I am"
=cut

print "AND I AM HIDDEN CODE INSIDE A HEREDOC";

=head2 BOO

but hey, if the pod inside a heredoc gets eaten by a pod parser (as it shoulD)
I see no problem here

=cut

A_TEST

}

1; ### end of modules

__END__

print "AND THIS WOULD STILL BE HIDDEN CODE";