in reply to Pod::Stripper

Sample perl script to strip.
#!/usr/bin/perl -w # testpod.pl use strict; =head1 test to be stripped =cut print "everything fine\n"; =head1 another test to be stripped =cut print "end\n";
I made a stripper.pl script with
#!/usr/bin/perl -w use strict; use Stripper; my $Stripper = new Pod::Stripper(); $Stripper->parse_from_filehandle(\*STDIN) unless (@ARGV); for my $ARGV (@ARGV) { $Stripper->parse_from_file($ARGV); }
The Stripper will output
#!/usr/bin/perl -w use strict; print "end\n";
(missing one line of code)
Then I made a poor man's stripper, as follows:
#!/usr/bin/perl -w use strict; my $inside_pod = 0; while (<>){ if ($inside_pod) { $inside_pod = ! /^=cut/; next; } else { $inside_pod = /^=\w/; } print unless $inside_pod; }
and the output contains the print "everything fine\n"; line.
However, the poor man's stripper will be fooled by such a sequence:
my $var =' =test ';
I know that POD tags should be isolated (i.e separated by "\n" before and after) but what if they don't? (As I found in some modules)
These POD tags are correctly ignored by the compiler, but make perldoc fail.
Is there any way of dealing with such tags?
_ _ _ _ (_|| | |(_|>< _|

Replies are listed 'Best First'.
Re: Re: Pod::Stripper
by crazyinsomniac (Prior) on Feb 03, 2002 at 11:44 UTC
    First off, thank you for your interest. This is a fundamental issue with perl pod.

    I will now quote from perlsyn

    PODs: Embedded Documentation

    Perl has a mechanism for intermixing documentation with source code. While it's expecting the beginning of a new statement, if the compiler encounters a line that begins with an equal sign and a word, like this

        =head1 Here There Be Pods!

    Then that text and all remaining text up through and including a line beginning with =cut will be ignored. The format of the intervening text is described in the perlpod manpage.

    This allows you to intermix your source code and your documentation text freely, as in

        =item snazzle($)
        The snazzle() function will behave in the most spectacular
        form that you can possibly imagine, not even excepting
        cybernetic pyrotechnics.
        =cut back to the compiler, nuff of this pod stuff!
        sub snazzle($) {
            my $thingie = shift;
            .........
        }

    Note that pod translators should look at only paragraphs beginning with a pod directive (it makes parsing easier), whereas the compiler actually knows to look for pod escapes even in the middle of a paragraph. This means that the following secret stuff will be ignored by both the compiler and the translators.

        $a=3;
        =secret stuff
         warn "Neither POD nor CODE!?"
        =cut back
        print "got $a\n";

    You probably shouldn't rely upon the warn() being podded out forever. Not all pod translators are well-behaved in this regard, and perhaps the compiler will become pickier.

    Now I will quote from perlpod

    Pod translators usually will require paragraphs to be separated by completely empty lines. If you have an apparently empty line with some spaces on it, this can cause odd formatting.
    Most people, and more importantly, parsers, choose to keep within the guidelines as demonstrated and explained by the pod above, and therefore so does Pod::Parser, and in turn Pod::Stripper as well.

    Is there any way of dealing with such tags?

    Why yes there is. I will probably be able to solve this issue by tinkering with Pod::Parser->preprocess_line and Pod::Parser->preprocess_paragraph and when I do, I will update Pod::Stripper to do a better job of stripping the pod, for all those dummies out there who can't follow guidelines. In the meantime, an immediate solution is to use Algorithm::Diff, and compare the output of Pod::Stripper and O->Deparse, as Deparse will strip "comments", but it is as smart as perl in figuring out what is actual code, and what is actual pod.

    Good looking out.

     
    ______crazyinsomniac_____________________________
    Of all the things I've lost, I miss my mind the most.
    perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"

(crazyinsomniac: fixed it) Re^2: Pod::Stripper
by crazyinsomniac (Prior) on Feb 12, 2002 at 12:40 UTC