The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Getopt::Long::Spec - translate Getopt::Long specs into a hash of attributes, and back again

VERSION

version 0.002

SYNOPSIS

  use Getopt::Long::Spec;

  my $gls = Getopt::Long::Spec->new;

  my %attrs = $gls->parse('foo|f=i@{3,4}');

  my $spec  = $gls->build(
    long         => 'foo',
    short        => 'f',
    val_required => 1,
    val_type     => 'int',
    dest_type    => 'array',
    min_vals     => 3,
    max_vals     => 4,
  );

DESCRIPTION

This dist provides a means of parsing Getopt::Long's option specifications and turning them into hashes describing the spec. Furthermore, it can do the inverse, turning a hash into an option spec!

Care has been taken to ensure that the output of "parse" can always be fed back into "build" to get the exact same spec - essentially round-tripping the spec passed to parse.

I'm not yet sure it works the other way arround, that the hashes are round-tripped, but I am less concerned with that for no other reason than the fact that the code is already twisted enough as it is to ensure the former situation. :)

METHODS

new

Simple constructor, takes no options.

parse

Given a valid Getopt::Long option specification, this method returns a hash describing the spec (see synopsis, above).

This can be called as an object or class method. It will throw an exception on any error parsing the spec.

build

Given a hash describing the attributes of a Getopt::Long option spec, builds and returns the spec described.

This can be called as an object or class method. It will throw an exception on any error interpreting the attributes in the hash, for example, if the attributes conflict with each other, or if they would result in building an option spec that GoL would reject.

The attributes that may be used are as follows:

WHY??!?

At some point I decided I wanted to create the ultimate command-line option processor. However, there are already so many out there, that I also wanted to be compatible with the most used of them. Since Getopt::Long is pretty much the de-facto standard in option processors, I realized, I need to make whatever I build able to use GoL's option specifications... hence this module.

AUTHOR

Stephen R. Scaffidi <sscaffidi@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Stephen R. Scaffidi.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.