NAME

Getopt::Base - foundation for oo GetOpt support

SYNOPSIS

package Getopt::YAWTDI;

use base 'Getopt::Base';
...

sub main {
  my $opt = Getopt::YAWTDI->new(%setup)->process(\@args) or return;

  my $foo = $opt->foo;
  ...
}

ABOUT

This module provides a foundation on which to build numerous forms of Getopt:: support, but does not supply any particular frontend.

ALPHA

This module is still growing. Your help with documentation and API suggestions are welcome.

Features

Modules built on this foundation will have the following features:

object-based output

The get() method returns an object with accessors. You may supply your own object.

loadable modes

A program (such as svn, svk, git) with multiple modes may cleanly load an additional set of options during @args processing.

long/short options, types, &c

Options are of the --long-form or the '-s' (short form). Short options may be bundled (opterand must follow the bundle.) Long options can be give in one or two-word form (e.g. '--opt=foo' or '--opt foo'.) Options may be 'typed' as boolean/string/integer/float and and be of the single or multi-element array/hash form. All boolean-type options automatically support the '--no-foo' negated form.

ordered callbacks

Items in actions will be triggered in as-defined order before any of the items in options are processed. This allows for e.g. loading config files or printing help/version messages.

cleanly callable

It should not be necessary for any callbacks to exit(). If one of them called stop(), then get() returns false and the caller should do the same. Errors will throw an error with croak().

Constructor

new

my $go = Getopt::Base->new(%setup);

_prepare

$self->_prepare(%params);

Methods

process

Process the @argv, removing options and opterands in-place.

my $obj = $go->process(\@argv) or return;

The storage object may also be passed explicitly.

$obj = $go->process(\@argv, object => $obj) or return;

Controlling process()

stop

Stops the option processing when called from an action handler. Always returns false.

$go->stop;

This is used for some forms of two-stage processing, where an action or argument indicates that all of the remaining inputs are to be handled elsewhere.

quit

Stops the option processing and prevents process() from returning an object . Always returns false.

$go->quit;

This is used for options like --version and --help, where you have a terminal action.

Handling Inputs

process_option

$self->process_option($name, \@argv);

process_arg

$self->process_arg($arg);

Setup

add_option

Add an option.

$go->add_option(name => %settings);

add_positionals

$go->add_positionals(@list);

add_aliases

$go->add_aliases($canonical => \@short, @list);

store

$go->store(key => $value, $value2, ...);

_checker

Builds a check subref for the given $name.

my $subref = $self->_checker($name);

set_values

$go->set_values(%hash);

object

Default/current result-storage object. Subclasses may wish to override this.

my $obj = $go->object;

make_object

Constructs an empty (with defaults) data object from the set options.

my $obj = $self->make_object;

_find_option

Fetches the option data for the canonical match (de-aliased) of $opt.

my $d = $self->_find_option($opt);

_unbundle

my @d = $self->_unbundle($blah);

Accessor Class

This is the default object for holding results. It will contain accessors for all of the defined options.

new

my $o = Getopt::Base::Accessors->new($opt_data);

AUTHOR

Eric Wilhelm @ <ewilhelm at cpan dot org>

http://scratchcomputing.com/

BUGS

If you found this module on CPAN, please report any bugs or feature requests through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

If you pulled this development version from my /svn/, please contact me directly.

COPYRIGHT

Copyright (C) 2009 Eric L. Wilhelm, All Rights Reserved.

NO WARRANTY

Absolutely, positively NO WARRANTY, neither express or implied, is offered with this software. You use this software at your own risk. In case of loss, no person or entity owes you anything whatsoever. You have been warned.

LICENSE

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