Getopt::Inherited - Handling inherited command-line options


Getopt-Inherited documentation  | view source Contained in the Getopt-Inherited distribution.

Index


NAME

Top

Getopt::Inherited - Handling inherited command-line options

VERSION

Top

version 1.100860

SYNOPSIS

Top

    use base 'Getopt::Inherited';

    use constant GETOPT => qw(foo=s);
    my $app = __PACKAGE__->new;
    $app->do_getopt;

DESCRIPTION

Top

By subclassing this mixin class, your program gets the ability to inherit command-line option specifications. If you have several programs that share common code and common command-line options you don't want to have to write the command-line processing code again and again. Using this class you can abstract command-line options shared by your programs into a superclass from which your programs then inherit. Additionally, this class defines certain common command-line options itself.

You can also define defaults for command-line options.

METHODS

Top

GETOPT

This accessor, which is accumulated across the class hierarchy using Data::Inherited, is used to define command-line options in the same format as Getopt::Long expects. This class, Getopt::Inherited, itself defines the following options:

    use constant GETOPT =>
        (qw(help man logfile|log=s verbose|v+ version|V));

GETOPT_DEFAULTS

This accessor, which is also accumulated across the class hierarchy, can be used to define defaults for the options given in GETOPT(). For example, to define a command-line option called <foo> which takes a string and to give it a default, you would use:

    use constant GETOPT => qw(foo=s);
    use constant GETOPT_DEFAULTS => (foo => 'my_default');

opt

This is a hash accessor per Class::Accessor::Complex in which the option hash is stored when it has been parsed and after default values have been applied.

usage

This method is called by do_getopt() after the command-line options have been processed with Getopt::Long's GetOptions. It uses Pod::Usage to display help information if there was either an error during processing, or if the --help or --man options have been given.

do_getopt

Does the actual command-line processing. It accumulates the values of GETOPT() across the hierarchy, parses them, calls usage() if necessary, applies GETOPT_DEFAULTS(), then assigns the finished options hash to opt().

INSTALLATION

Top

See perlmodinstall for information and options on installing Perl modules.

BUGS AND LIMITATIONS

Top

No bugs have been reported.

Please report any bugs or feature requests through the web interface at http://rt.cpan.org/Public/Dist/Display.html?Name=Getopt-Inherited.

AVAILABILITY

Top

The latest version of this module is available from the Comprehensive Perl Archive Network (CPAN). Visit http://www.perl.com/CPAN/ to find a CPAN site near you, or see http://search.cpan.org/dist/Getopt-Inherited/.

The development version lives at http://github.com/hanekomu/Getopt-Inherited/. Instead of sending patches, please fork this project using the standard git and github infrastructure.

AUTHOR

Top

  Marcel Gruenauer <marcel@cpan.org>

COPYRIGHT AND LICENSE

Top


Getopt-Inherited documentation  | view source Contained in the Getopt-Inherited distribution.