# The following was supposedly scribed by
# [EMAIL PROTECTED]
# on Saturday 26 June 2004 05:31 am:
>Andy mentioned Getopt::Declare. I've briefly taken a look at it a few
>times, and I did so again when he mentioned it. I guess I never really
>"got it". It doesn't seem to solve the problem, but since I've been
>thing about tighter perl/pod integration, it occurs to me that a natural
>extension of Getopt::Decare's functionality would be to have it get its
>specification from pod
It's an interesting functionality, but the trouble with having the options
come from the pod is that you don't get to make perl do any of the work.
I've taken a crack at this and it seems that maybe its a two-part problem.
Part one is tying the documentation to the option declaration, while part two
is dynamically generating the pod (yes, Getopt::Declare skips part two, but
again, I'm stubborn and want to make the computer earn its keep.)
This is only partly underway, but feel free to look at the bloody stump of
code at http://ericwilhelm.homeip.net/svn/Getopt-Helpful/trunk/code/Getopt/
$example = <<'END';
use Getopt::Long;
# this doesn't replace Getopt::Long, just supplements it
use Getopt::Helpful;
my $name;
my $ext = ".dwg";
my $parts = "parts/";
my $force = 0;
my $hopt = Getopt::Helpful->new(
['n|name=s', \$name, '',
"name for new part"],
['p|parts=s', \$parts, '',
"directory containing parts (default $parts)"],
['e|ext=s', \$ext, '.',
"extension for geometry file (default $ext)"],
['f|force',\$force, ' ',
"force overwrite of existing files (default: " .
($force ? "yes" : "no") . ")"],
);
GetOptions(
$hopt->opts,
);
END
The documentation part isn't ready yet, but it would be something like
$hopt->help_string() and would return a string which joins the 0,2, and 3
indices of the input data (padding the columns and maybe turning 'f|force'
into '-f, --force', giving something like:
-e, --ext extension for geometry file
-f, --force, --noforce force overwrite of existing files (default: no)
I'm not super happy with the array-reference interface (it assumes a lot and
lines tend to need a lot of re-wrapping), but it gets everything into one
place rather than scattered about and allows the variables to tell the user
their default values (even solving the side-effect that Johan pointed
out.) It also allows you to maintain an order, which a hash wouldn't.
Also, I'd welcome suggestions on the name, since Getopt:: doesn't really
describe the functionality (except that it is related to option getting.)
--Eric
--
"Cleanliness is next to impossible."
--Unknown