|
Getopt::Std::WithCheck - Perl extension for process command line arguments with custom check on them |
Getopt::Std::WithCheck - Perl extension for process command line arguments with custom check on them
use Getopt::Std::WithCheck;
my %opts = ('d' => {'argument' => 0,
'default' => 0,
'description' => "Print debug info",
},
);
my %CFG = %{Getopt::Std::WithCheck::getOpts('programName', "Example of Getopt::Std::WithCheck usage\n\n", \%opts)};
if ($CFG{'d'})
{
print STDERR Getopt::Std::WithCheck::usage();
};
Getopt::Std::WithCheck provides a simple way to proccess command line arguments check.
Also, basic ``usage'' functionality provided.
getOpts($programName, $programDescription, $PARAMHASHREF);checkRoutine (see below) is called for each parameter to check it.
Die with usage message in case of required parameter is not defined.
Parameters of this method are
$programNameusage message.
$programDescriptionusage message
Values must be a reference to hash describing parameter
This parameter description should contain following keys:
argumentDefault is not to take argument.
defaultNote: you can set default to undef to indicate required parameter.
In case required parameter is not provided getOpts(); method will die with usage message.
Default is undef
descriptionusage message.
Default is empty string.
checkRoutineCalled with one argument - the parameter itself. Value returned is used as parameter value.
Default routine is simple return parameter back to use it as is.
Note: if 'h' parameter is not specified, default procedure is used for it.
Default procedure is to print usage message to STDERR and exit with 0 exit code.
In addition to parameters processing getOpts creatina an usage message.
This message is stored inside of module and can be accesses by usage method.
getOpts($programName, $programDescription, $PARAMLISTREF);getOpts.
@{$PARAMLISTREF} should contain parameters description
$PARAMLISTREF->[0]%{$PARAMHASHREF}
%{$PARAMHASHREF} is used as parameters description
$PARAMLISTREF->[1]argument in %{$PARAMHASHREF}
$PARAMLISTREF->[2]default in %{$PARAMHASHREF}
$PARAMLISTREF->[3]description in %{$PARAMHASHREF}
$PARAMLISTREF->[4]checkRoutine in %{$PARAMHASHREF}
usage($programName, $programDescription, $PARAMHASHREF);getOpts).
usage($programName, $programDescription, $PARAMLISTREF);getOpts).
usage()usage or getOpts.
None by default.
Daniel Podolsky, <tpaba@cpan.org>
Copyright (C) 2007 by Daniel Podolsky, <tpaba@cpan.org>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available.
|
Getopt::Std::WithCheck - Perl extension for process command line arguments with custom check on them |