# depod - filter Perl pod constructs from text.
# Copyright 1999 Nathan Scott Thompson ( quimby at city-net dot com )
# You may use this according to the GNU Public License: see http://www.gnu.org
# Hope you have fun with this and maybe even find it useful.
# Documentation at bottom.

$ignore = join '|', 
        qw/ ARGV ENV INC ISA LOGDIR PERL5DB PERL5LIB PERL5OPT PERLLIB
        SIG STDERR STDIN STDOUT
        abs atan2 autouse binmode blib chdir chmod chown chr
        chroot closedir cmp cos dbmclose dbmopen elsif eof eq eval exec exp
        fcntl fileno flock foreach formline 
        ge get(c|login|peername|ppid|sockname)
        get(host|net|serv|proto)(byaddr|byname)
        get(pw|gr)(nam|uid) 
        (get|set)(pgrp|priority|sockopt)
        (get|set|end)(pw|gr|host|net|serv|proto)ent
        glob gmtime goto grep gt int ioctl isa
        lc lcfirst le lib localtime lstat lt
        mkdir msg(ctl|get|snd|rcv) ne oct opendir ops ord perl pos printf 
        quotemeta rand readdir readlink recv ref rewinddir rindex rmdir
        seekdir sem(ctl|get|op) shm(ctl|get|read|write) shutdown sigtrap
        socketpair sprintf sqrt srand stat substr symlink 
        sys(call|open|read|seek|write) telldir uc ucfirst umask undef utime
        vars vec vmsish waitpid wantarray xor /;

if ( $ARGV[0] eq '-w' )
{
    $Words_Only = 1;
    shift;
}

while ( <> )
{
    if ( /^=[^c]/ .. /^=cut/ )
    {
        s/^=(head\d+|item)\s+//;                # save text from head or item
        /^=/ and next;                          # ditch other pod directives
        s/E<[^>]*>/ /g;                         # replace escapes
        1 while s/[A-Z]<[^<>]*>//;              # remove interior sequences

        if ( $Words_Only )
        {
            s/[\$%@&*]\S+//g;                   # remove variable-like things
            s/\b($ignore)\b//go;                # remove perlish words
            print $&, "\n" while /\b[A-Za-z][A-Za-z\d']*[A-Za-z\d]\b/g;
        }
        else
        {
            print;
        }
    }
}

1;

__END__

=head1 NAME

depod - extract text from Perl pods

=head1 SYNOPSIS

 depod [ -w ] [ file ] ...

=head1 DESCRIPTION

B<depod> reads the given files (or standard input) and removes pod
directives (e.g. `=head1') and prints the text between a starting
directive and `=cut'.

The B<-w> flag causes B<depod> to print only words, one per line.
Words are considered to start with a letter and contain letters,
digits or apostrophes (but no trailing apostrophes.)
Single character words are ignored.
Perl keywords and function names are also ignored, along with 
whatever looks like a variable: this produces a list suitable for B<spell>,

=head1 SEE ALSO

 spell
 pod2text

=head1 BUGS

Doesn't attempt to interpret pod syntax; just a braindead filter for B<spell>.
