Getopt::LL::Short
Index
Code Index:
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 78
# End:
# vim: expandtab tabstop=4 shiftwidth=4 shiftround
# $Id: Short.pm,v 1.6 2007/07/13 00:00:14 ask Exp $
# $Source: /opt/CVS/Getopt-LL/lib/Getopt/LL/Short.pm,v $
# $Author: ask $
# $HeadURL$
# $Revision: 1.6 $
# $Date: 2007/07/13 00:00:14 $
package Getopt::LL::Short;
use strict;
use warnings;
use base 'Getopt::LL';
use version; our $VERSION = qv('1.0.0');
use 5.006_001;
{
use Getopt::LL::SimpleExporter qw(getoptions);
my %RULE_ABBREVATION = (
's' => 'string',
'd' => 'digit',
'f' => 'flag',
);
sub parse_short_rule {
my ($rule) = @_;
if (index ($rule, q{=}) != -1) {
my ($arg_name, $rule_type) = split m/=/xms, $rule, 2;
return ($arg_name, $RULE_ABBREVATION{$rule_type});
}
# Default rule is flag.
return ($rule, 'flag');
}
sub getoptions {
my ($rules_ref, $options_ref, $argv_ref) = @_;
$rules_ref ||= [ ];
my %converted_rules;
for my $rule (@{$rules_ref}) {
my ($arg_name, $rule_ref) = parse_short_rule($rule);
$converted_rules{$arg_name} = $rule_ref;
}
return Getopt::LL::getoptions(
\%converted_rules, $options_ref, $argv_ref
);
}
}
1;
__END__