View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Eric Wilhelm > Getopt-Base-v0.0.3 > Getopt::Base



Annotate this POD


View/Report Bugs
Module Version: v0.0.3   Source  


Getopt::Base - foundation for oo GetOpt support


  package Getopt::YAWTDI;

  use base 'Getopt::Base';

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

    my $foo = $opt->foo;


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


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 ^


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



Methods ^


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() ^


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


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.


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


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

Handling Inputs ^


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



Setup ^


Add an option.

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




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


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


Builds a check subref for the given $name.

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




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

  my $obj = $go->object;


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

  my $obj = $self->make_object;


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

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


  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.


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


Eric Wilhelm @ <ewilhelm at cpan dot org>


If you found this module on CPAN, please report any bugs or feature requests through the web interface at 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 (C) 2009 Eric L. Wilhelm, All Rights Reserved.


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.


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

syntax highlighting: