Objectified Getopt::Long
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2022-11-17 16:51:50 +00:00
dist Add explicit Provides to spec 2022-11-17 16:51:50 +00:00
lib/Getopt Ensure lookup keys are all \w 2022-11-16 17:20:10 +00:00
LICENSE Initial commit 2020-11-21 10:13:51 +00:00
Makefile.PL Adjust spec file, include initial documentation 2021-02-17 23:37:22 +00:00
MANIFEST Initial commit 2020-11-21 10:13:51 +00:00
MANIFEST.SKIP Initial commit 2020-11-21 10:13:51 +00:00
README.md Ensure lookup keys are all \w 2022-11-16 17:20:10 +00:00

NAME

Getopt::Object - Simplified Getopt::Long as an object

VERSION

version 1.2

SYNOPSIS

use Getopt::Object;
use DBI;
use Pod::Usage;

my  $o = Getopt::Object->new(
    'help|?'            => 0,
    'man'               => 0,
    'verbose|v'         => 0,
    'debug'             => 0,
    'version'           => 0,
    'database|D=s'      => 'topsecret',
    'quiet|q'           => 0,
    'email|M'           => 0,
    );

$o->AddValues( 'handle' => undef );

$o->Getopts or pod2usage(2);
pod2usage(1) if $o->help;
pod2usage(-exitval => 0, -verbose => 2) if $o->man;

$o->handle( DBI->connect( $o->database ) );

DESCRIPTION

Getopt::Object is a simplied object form of Getopt::Long that uses Class::Accessorise to turn the options in object accessors. This provides a consistent object for accessing command options and as a side-effect ensures attempts to non-existent parameters results in an exception rather than use of an undefined vaule.

It also provides the ability to add additional non-command options to the object to allow for the holding of derived values. The result is a single object with accessor methods that can be safely passed where needed.

Methods

new

The new method takes multiple pairs of values consisting of a Getopt::Long Option Specification and the default value for same. As with Getopt::Long the stored name is the first in the list and should be valid as an identifier or method name. If it is not it will be folded to be valid in an attempt to just work but may clash with other options. It is safest to ensure that the first item in the Option Specification is simply valid. So, if you wish to also allow kebab-case as well as snake-case

'homedirectory|home_directory|home-directory|H'

AddValues

This method adds values accessors to the object takes pairs of accessor name and initial value.

Getopts

This method performs the actual Getopt::Long GetOptions call after building the default hash. If the call was successful it transfers the provided values back into the object. In all cases this method returns the result of the GetOptions call.

COMPATIBILITY

  • Getopt::Object requires Class::Accessorize and Getopt::Long

AUTHOR

Bernard Quatermass toolsmith@quatermass.co.uk

COPYRIGHT AND LICENSE

This software is copyright (c) 2020,2021,2022 by Bernard Quatermass.

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