memo.garciasir has asked for the wisdom of the Perl Monks concerning the following question:

I want to document my program inside the source file using Pod::Text.

This works fine using perl program.pl, but fails if I generate an executable file using pp.

Her is a a small script that show what happens.

#! /usr/bin/perl use warnings; use strict; use Pod::Text; use File::Basename; userManual(); sub userManual { # show user manual my $pod = basename $0; # the pod text is in the perl fi +lew my $tmp = getTMP(); # look for a temp file my $parser = Pod::Text->new (); # convert pod to text $parser->parse_from_file ($pod, $tmp); # do the convertion die "Can't open $tmp ($!)\n" unless (open (TXT, $tmp)); # OOPS while (<TXT>) { # display the text file print; } close TXT; # close the text file unlink $tmp; # and delete it } sub getTMP { use POSIX qw(tmpnam); my $name; do { $name = tmpnam() } until (! -e $name); # try until we get +one that didn't already exist return $name; } =pod =head1 PROGRAM NAME B<program> - This is the program =head1 DESCRIPTION The program B<program> bla bla bla bla bla bla bla bla bla bla bla bla + bla bla bla bla bla bla bla bla bla bla bla bla. =head1 AUTHOR memo garcia <mgarcia@cistrans.cl>. March, 2010 =cut

What Pod::Text is using as input file is the executable and not the perl code.

One solution is to separate the pod source in program.pod and use this as the input for Pod::Text, but I want to distribute one single file to the end user.

Any idea??

memo

Replies are listed 'Best First'.
Re: using Pod::Text and pp
by almut (Canon) on Mar 19, 2010 at 22:49 UTC

    You could try putting the POD in a __DATA__ section, and then use

    use Pod::Text; my $parser = Pod::Text->new(); $parser->output_fh(*STDOUT); # or $parser->output_string( \my $out ); $parser->parse_file(*DATA); __DATA__ = pod ...

    The idea would be that the DATA handle (as opposed to basename $0) is pointing to the properly unpacked source...  (untested, though)

    P.S.: the parse_file() method is inherited from Pod::Simple, which means you need a reasonably new version of Pod::Text (older ones didn't subclass Pod::Simple, IIRC).

      Thanks, your tip works fine.

Re: using Pod::Text and pp
by Anonymous Monk on Mar 20, 2010 at 02:53 UTC