On 6/24/2004 11:11 PM, Eric Wilhelm wrote:

Hi everybody!

I'm going to be documenting a system of (30+) programs with is mostly scripts, rather than modules. I know you can just put pod text in your scripts, but I'd like to also integrate the usage messages into the pods (or get them from the pods.)

I've seen pod2usage() and this would work, but most of these scripts have some defaults set for variables that can be changed with the GetOptions flags and I'd like to show these defaults at least in the help message.

Example:

my $rounding = 0.01;

GetOptions(
        'round=f' => \$rounding,
        'help'       => sub {usage()},
        );

sub usage {
        print "usage:  $0 <filename>\n";
        print "options:  --round <float>   (default  $rounding)\n";
}
END

Since the strings printed by usage() in this case are generated on the fly, the values which have already been set are available to be printed. With pod2usage() and perldoc, this is not the case. Is there any way to make this work without having to maintain duplicate information?

Preferably, something that would try to do() the file up to a certain point, gather the variables and perform a substitution (maybe on a tag like v<$rounding>.)

Yeah, I alway thought that was a weakness of the core pod modules. Fortunately, it's easy to subclass them to do what you want. You'll want to subclass Pod::Text, override the proper method to add a new escape sequence (say $<variable_name>), then maybe override the constructor to take a hash with the values for the variables or possibly something more elaborate like evaling the variable name in the caller's context.


I've done similary on several occasions and it is fairly trivial. If you have trouble, I can probably dig up an example.

Randy.




Reply via email to