NAME

MooX::Options - add option keywords to your object (Mo/Moo/Moose)

VERSION

version 3.77

MooX::Options

Use Getopt::Long::Descritive to provide command line option for your Mo/Moo/Moose Object.

This module will add "option" which act as "has" but support additional feature for getopt.

You will have "new_with_options" to instanciate new object for command line.

METHOD

IMPORT

The import method can take option :

USAGE

First of all, I use Getopt::Long::Descriptive. Everything will be pass to the programs, more specially the format.

{
    package t;
    use Moo;
    use MooX::Options;

    option 'test' => (is => 'ro');

    1;
}

my $t = t->new_with_options(); #parse @ARGV
my $o = t->new_with_options(test => 'override'); #parse ARGV and override any value with the params here

The keyword "option" work exactly like the keyword "has" and take extra argument of Getopt.

You can also use it over a Role.

{
    package tRole;
    use Moo::Role;
    use MooX::Options;

    option 'test' => (is => 'ro');

    1;
}

{
    package t;
    use Moo;
    use MooX::Options; #you have to add this, or the role will not find the necessary methods
    with 'tRole';
    1;
}

my $t = t->new_with_options(); #parse @ARGV
my $o = t->new_with_options(test => 'override'); #parse ARGV and override any value with the params here

If you use Mo, you have a little bit more work to do. Because Mo lack of "with" and "around".

{
    package tRole;
    use Moo::Role;
    use Mo;
    use MooX::Options;

    option 'test' => (is => 'ro');
    1;
}
{

    package t;
    use Mo;
    use Role::Tiny::With;
    with 'tRole';

    1;
}
my $t = t->new_with_options(); #parse @ARGV
my $o = t->new_with_options(test => 'override'); #parse ARGV and override any value with the params here

It's a bit tricky but, hey, you are using Mo !

Keyword 'options_usage'

It display the usage message and return the exit code

my $t = t->new_with_options();
$t->options_usage(1, "str is not valid");

Params :

Keyword 'new_with_options'

It will parse your command line params and your inline params, validate and call the 'new' method.

You can override the command line params :

Ex:

local @ARGV=('--str=ko');
t->new_with_options(str => 'ok');
t->str; #ok

Keyword 'option' : EXTRA ARGS

namespace::clean

dash support

no more Mouse support

More examples

THANKS

BUGS

AUTHOR

COPYRIGHT AND LICENSE