At 14:10 29/09/2004 +0200, Thomas Klausner wrote:

Nicholas, while I think you're idea of repleacing POD with comments to keep
line numbers correct is good, I didn't found time to dig into Pod::Simple to
find out how to implement this. (patches welcome)


Here is a one-line patch that puts in #line directives as per Nicholas' suggestion. Maybe it should be made optional, you can decide that. ;-)

It probably shouldn't put unnecessary directives on sequential lines either. I might fix that later.



--- Strip.pm    Wed Sep 29 12:04:14 2004
+++ Strip2.pm   Wed Sep 29 21:04:55 2004
@@ -12,6 +12,7 @@
     $new->code_handler
       (
        sub {
+          print "#line ", $_[1],"\n" if $_[0] =~ /\S/;
           print {$_[2]{'output_fh'}} $_[0],"\n";
           return;
        });



Anyway, here is a simple pod stripper using Pod::Strip:

    #!/usr/bin/perl -w


    use strict;
    use Pod::Strip;


    my $parser = Pod::Strip->new();


    if (defined $ARGV[0]) {
        open IN, $ARGV[0]  or die "Couldn't open $ARGV[0]: $!\n";
    } else {
        *IN = *STDIN;
    }

    if (defined $ARGV[1]) {
        open OUT, ">$ARGV[1]" or die "Couldn't open $ARGV[1]: $!\n";
    } else {
        *OUT = *STDOUT;
    }


    $parser->output_fh(*OUT);
    $parser->parse_file(*IN);


    __END__


And here is the effect of the patch:



    $ cat -n podfile1.pl
    1       #!/usr/bin/perl -wl
    2
    3       =head1 NAME
    4
    5       101 reasons to hate inline Pod.
    6
    7       =cut
    8
    9       my $way = 'best';
    10
    11      =head1 REASON 1
    12
    13      Pod is for users to read.
    14      Comments are for programmers to read.
    15
    16      =cut
    17
    18      die "Died young";
    19
    20      __END__
    21
    22

    $ perl podfile1.pl
    Died young at podfile1.pl line 18.



    $ perl podstrip.pl podfile1.pl > podfile2.pl

    $ cat -n podfile2.pl
    1       #line 1
    2       #!/usr/bin/perl -wl
    3
    4
    5       #line 9
    6       my $way = 'best';
    7
    8
    9       #line 18
    10      die "Died young";
    11
    12      #line 20
    13      __END__
    14
    15

    $ perl podfile2.pl
    Died young at podfile2.pl line 18.


Still dies young at eighteen. How sad.

John.
-
-

Reply via email to