Bob Rogers said:
> easier to add command-line options through class inheritance and reuse
> than it is to document them. I have attached an early version of the
Hm, I've been using Getopt::Declare for a lot of
command-line scripts at work. I'm not a webhead,
I do command line tools, so command line options
is my bread and butter.
Getopt::Declare lets you document and design your
command line arguments in one simple text string.
This will probably get mangled, but it looks something
like this:
my $interface = <<'INTERFACE' ;
-in <filename> Specify an input file
{ $main::in = $filename; }
INTERFACE
You then take this gigantic string and pass it
to Getopt::Declare which parses the command
line arguments, executes any actions your interface
has defined, and returns an object you can use later.
see "Impatient Perl" section 17.2
http://www.greglondon.com/iperl/html/iperl.html#17.2.Getopt::Declare
Getopt::Declare also handles the -help option for
you automatically, printing out the string you
used to declare your options as your help text.
So, you get some freebies usign it.
I've been running into situations where I have
modules that use certain command line options,
and I've been toying with the idea of somehow
defining each module's options in a separate
string, and then having some way that "inherits"
all these strings into one massive string that
can then be used in your main script.
But its usually one or two modules so it's never
been a burning issue enough for me to actually code
something up.
You might be able to have a BEGIN block in every module
that concatenates their specific string to some agreed-upon
variable, and then when you "use" a module and all of its
base classes, you will end up with a string somewhere that
should be usable by Getopt::Declare and should also act
as your documentation/help.
package MyModule;
BEGIN
{
$main::Getopt_Declare_String .= <<'INTERFACE';
-in <filename> Specify an input file
{ $main::in = $filename; }
INTERFACE
}
# put your module methods and constructors here
1;
Then, somewhere in you main script, you could
have an INIT block that takes the Getop_Declare_String
and passes it to Getopt::Declare.
Every module that gets used will concatenate
their piece of text to the getopt declare string
at BEGIN time, and then at CHECK time, the string
should be a complete declaration of all options all
the modules need, and you should be able to pass
it to getopt declare to do the actual parsing.
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm