NAME
Getopt::Std::WithCheck - Perl extension for process command line arguments with custom check on them
SYNOPSIS
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();
};
DESCRIPTION
Getopt::Std::WithCheck provides a simple way to proccess command line arguments check.
Also, basic "usage" functionality provided.
The Getopt::Std::WithCheck methods
getOpts($programName, $programDescription, $PARAMHASHREF);
-
Returns a hash contains all the parameters with values set in command line or provided by default.
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
$programName
-
Name of the program, will be used in
usage
message. $programDescription
-
Description of the program, will be used in
usage
message - $PARAMHASHREF
-
%{$PARAMHASHREF} contains the letters will be used for command line options as keys.
Values must be a reference to hash describing parameter
This parameter description should contain following keys:
argument
-
Boolean value indicated will this parameter followed by argument or not.
Default is not to take argument.
default
-
Default value for this parameter.
Note: you can set
default
toundef
to indicate required parameter. In case required parameter is not providedgetOpts();
method will die withusage
message.Default is
undef
description
-
Description of this parameter. will be used in
usage
message.Default is empty string.
checkRoutine
-
Reference to a subroutine called to check a validity of this paramneter.
Called 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 printusage
message toSTDERR
and exit with0
exit code.
In addition to parameters processing
getOpts
creatina an usage message. This message is stored inside of module and can be accesses byusage
method. getOpts($programName, $programDescription, $PARAMLISTREF);
-
Another form of
getOpts
.@{$PARAMLISTREF}
should contain parameters description$PARAMLISTREF->[0]
-
Parameter letter, like a key in
%{$PARAMHASHREF}
%{$PARAMHASHREF}
is used as parameters description $PARAMLISTREF->[1]
-
Boolean value indicated will this parameter followed by argument or not, like a
argument
in%{$PARAMHASHREF}
$PARAMLISTREF->[2]
-
Default value for this parameter, like a
default
in%{$PARAMHASHREF}
$PARAMLISTREF->[3]
-
Description for this parameter, like a
description
in%{$PARAMHASHREF}
$PARAMLISTREF->[4]
-
Check routine for this parameter, like a
checkRoutine
in%{$PARAMHASHREF}
usage($programName, $programDescription, $PARAMHASHREF);
-
returns a usage message based on parameters passed (see
getOpts
). usage($programName, $programDescription, $PARAMLISTREF);
-
returns a usage message based on parameters passed (see
getOpts
). usage()
-
returns a usage message based on previous call of
usage
orgetOpts
.
EXPORT
None by default.
SEE ALSO
AUTHOR
Daniel Podolsky, <tpaba@cpan.org>
COPYRIGHT AND LICENSE
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.