Getopt-LL

 view release on metacpan or  search on metacpan

lib/Getopt/LL/Short.pm  view on Meta::CPAN

# $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__

=for stopwords expandtab shiftround

=begin wikidoc

= NAME

Getopt::LL::Short - Abbreviated Getopt::LL rules.

= VERSION

This document describes Getopt::LL version %%VERSION%%

= SYNOPSIS

    use Getopt:LL::Short qw(getoptions);

    my $options = getoptions([
        '-t=s',             # a string
        '--use-foo=f',      # a flag
        '--verbose|-v',     # also a flag
        '--debug=d|-d',     # a digit
    });

= DESCRIPTION

This is a subclass of Getopt::LL that allows for abbreviated rules.

= SUBROUTINES/METHODS


== CONSTRUCTOR



( run in 1.437 second using v1.01-cache-2.11-cpan-71847e10f99 )