Stephen R. Scaffidi > Getopt-Long-Spec > Getopt::Long::Spec::Parser

Download:
Getopt-Long-Spec-0.002.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.002   Source  

NAME ^

Getopt::Long::Spec::Parser - Parse a Getopt::Long option spec into a set of attributes

VERSION ^

version 0.002

SYNOPSIS ^

This module parses an option specification as would normally be used with Getopt::Long, and produces a hash showing the meaning/parameters the spec describes... if that makes any sense at all...

Perhaps a little code snippet.

    use Getopt::Long::Spec::Parser;

    my $parser = Getopt::Long::Spec::Parser->new();
    my %spec_info = $parser->parse( 'foo|f=s@{1,5}' );

    # OR...

    my %spec_info =
        Getopt::Long::Spec::Parser->parse( 'foo|f=s@{1,5}' );

%spec_info should be a hash containing info about the parsed Getopt::Long option specification

METHODS ^

new

construct a new parser.

    my $parser = Getopt::Long::Spec::Parser->new();
    # OR...
    my $parser = Getopt::Long::Spec::Parser->new(
        debug => 1,
    );

parse

parse an option specification

    my %spec_info = $parser->parse( 'foo' );
    # OR...
    my %spec_info = Getopt::Long::Spec::Parser->parse( 'foo' );

return the info parsed from the spec as a hash, or hashref, depending on context.

In scalar context, returns a hashref, in list context, returns a hash.

NOTES on PARSING Getopt::Long OPTION SPECIFICATIONS ^

Described as a grammar:

  opt_spec  ::=  name_spec (arg_spec)?  # if no arg_spec, option is a flag.

  name_spec ::=  opt_name ("|" opt_alias)*
  opt_alias ::=  /\w+/
  opt_name  ::=  /\w+/

  arg_spec  ::= "="  val_type                (dest_type)? (repeat)?  # simple required
              | ":" (val_type | /\d+/ | "+") (dest_type)?            # simple optional
              | "!"                                                  # flag negatable
              | "+"                                                  # flag incremental

  arg_type  ::=  "s" | "i" | "o" | "f"              # string, integer, extint, float
  dest_type ::=  "@" | "%"                          # array or hash
  repeat    ::=  "{" (min_val)? ("," max_val)? "}"  # multiple-values per use
  min_vals  ::=  /\d+/
  max_vals  ::=  /\d*/

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.

syntax highlighting: