Getargs::Long 1.1001 review

Download
by rbytes.net on

Getargs::Long is a Perl module with named subroutine arguments, with optional type checking. SYNOPSIS use Getargs::Long;

License: Perl Artistic License
File size: 40K
Developer: Raphael Manfredi
0 stars award from rbytes.net

Getargs::Long is a Perl module with named subroutine arguments, with optional type checking.

SYNOPSIS

use Getargs::Long; # case sensitive
use Getargs::Long qw(ignorecase); # case insensitive

# Simple, args mandatory
my ($val, $other) = getargs(@_, qw(val other));

# Simple, args optional (in [] means optional)
my ($val, $other) = getargs(@_, [qw(val other)]);

# Simple with typechecking, args mandatory
my ($val, $other) = getargs(@_, qw(val=Class::X other=ARRAY));

# Simple with typechecking, args optional
my ($val, $other) = getargs(@_, [qw(val=Class::X other=ARRAY)]);

# Faster version, building dedicated argument parsing routine
my ($val, $other) = cgetargs(@_, qw(val other));

# Other cases, use full specs:
my ($x, $y, $z, $a, $b, $c) = xgetargs(@_,

# Non-mandatory, defaults to undef unless specified otherwise
'x' => ['i'], # integer, no default
'y' => ['ARRAY', ['a', 'b']], # Has a default
'z' => [], # No typecheck, can be anything

# Mandatory arguments
'a' => 'i', # integer (scalar)
'b' => 'TYPE', # TYPE or any heir of TYPE
'c' => undef, # unspecified type but mandatory
);

# Extract remaining unparsed args in @extra
my ($val, $other, @extra) = getargs(@_, { -strict => 0 }, qw(val other));

# Alter behaviour of the getargs() routines via switches in hashref
my ($val, $other) = getargs(@_,
{
-strict => 1, # unknown switches are fatal
-ignorecase => 1, # override package's global
-inplace => 1, # edit @_ inplace: remove parsed args
-extra => 0, # suppress return of extra arguments
},
qw(val other)
);

The Getargs::Long module allows usage of named parameters in function calls, along with optional argument type-checking. It provides an easy way to get at the parameters within the routine, and yields concise descriptions for the common cases of all-mandatory and all-optional parameter lists.

The validation of arguments can be done by a structure-driven routine getargs() which is fine for infrequently called routines (but should be slower), or via a dedicated routine created and compiled on the fly the fist time it is needed, by using the cgetargs() family (expected to be faster).

The Log::Agent module is used to report errors, which leaves to the application the choice of the final logging method: to a file, to STDERR, or to syslog.

Requirements:
Perl

Getargs::Long 1.1001 keywords