Coder Social home page Coder Social logo

moox-options's Introduction

NAME

MooX::Options - Explicit Options eXtension for Object Class

SYNOPSIS

In myOptions.pm :

package myOptions;
use Moo;
use MooX::Options;

option 'show_this_file' => (
    is => 'ro',
    format => 's',
    required => 1,
    doc => 'the file to display'
);
1;

In myTool.pl :

use myOptions;
use Path::Class;

my $opt = myOptions->new_with_options;

print "Content of the file : ",
     file($opt->show_this_file)->slurp;

To use it :

perl myTool.pl --show_this_file=myFile.txt
Content of the file: myFile content

The help message :

perl myTool.pl --help
USAGE: myTool.pl [-h] [long options...]

    --show_this_file: String
        the file to display

    -h --help:
        show this help message

    --man:
        show the manual

The usage message :

perl myTool.pl --usage
USAGE: myTool.pl [ --show_this_file=String ] [ --usage ] [ --help ] [ --man ]

The manual :

perl myTool.pl --man

DESCRIPTION

Create a command line tool with your Mo, Moo, Moose objects.

Everything is explicit. You have an option keyword to replace the usual has to explicitly use your attribute into the command line.

The option keyword takes additional parameters and uses Getopt::Long::Descriptive to generate a command line tool.

IMPORTANT CHANGES IN 4.100

Enhancing existing attributes

One can now convert an existing attribute into an option for obvious reasons.

package CommonRole;

use Moo::Role;

has attr => (is => "ro", ...);

sub common_logic { ... }

1;

package Suitable::Cmd::CLI;

use Moo;
use MooX::Cmd;
use MooX::Options;

with "CommonRole";

option '+attr' => (format => 's', repeatable => 1);

sub execute { shift->common_logic }

1;

package Suitable::Web::Request::Handler;

use Moo;

with "CommonRole";

sub all_suits { shift->common_logic }

1;

package Suitable::Web;

use Dancer2;
use Suitable::Web::Request::Handler;

set serializer => "JSON";

get '/suits' => sub {
    $my $reqh = Suitable::Web::Request::Handler->new( attr => config->{suit_attr} );
    $reqh->all_suits;
};

dance;

1;

Of course there more ways to to it, Jedi or Catalyst shall be fine, either.

Rename negativable into negatable

Since users stated that negativable is not a reasonable word, the flag is renamed into negatable. Those who will 2020 continue use negativable might or might not be warned about soon depreciation.

Replace Locale::TextDomain by MooX::Locale::Passthrough

Locale::TextDomain is broken (technically and functionally) and causes a lot of people to avoid MooX::Options or hack around. Both is unintened.

So introduce MooX::Locale::Passthrough to allow any vendor to add reasonable localization, eg. by composing MooX::Locale::TextDomain::OO into it's solution and initialize the localization in a reasonable way.

Make lazy loaded features optional

Since some features aren't used on a regular basis, their dependencies have been downgraded to recommended or suggested. The optional features are:

  • autosplit

    This feature allowes one to split option arguments at a defined character and always return an array (implicit flag repeatable).

      option "search_path" => ( is => "ro", required => 1, autosplit => ":", format => "s" );
    

    However, this feature requires following modules are provided:

  • json format

    This feature allowes one to invoke a script like

      $ my-tool --json-attr '{ "gem": "sapphire", "color": "blue" }'
    

    It might be a reasonable enhancement to handles.

    Handling JSON formatted arguments requires any of those modules are loded:

Decouple autorange and autosplit

Until 4.023, any option which had autorange enabled got autosplit enabled, too. Since autosplit might not work correctly and for a reasonable amount of users the fact of

$ my-tool --range 1..5

is all they desire, autosplit will enabled only when the dependencies of autosplit are fulfilled.

IMPORTED METHODS

The list of the methods automatically imported into your class.

new_with_options

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

myTool --str=ko

t->new_with_options()->str # ko
t->new_with_options(str => 'ok')->str #ok

option

The option keyword replaces the has method and adds support for special options for the command line only.

See "OPTION PARAMETERS" for the documentation.

options_usage | --help

It displays the usage message and returns the exit code.

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

This method is also automatically fired if the command option "--help" is passed.

myTool --help

options_man | --man

It displays the manual.

my $t = t->new_with_options();
$t->options_man();

This is automatically fired if the command option "--man" is passed.

myTool --man

options_short_usage | --usage

It displays a short version of the help message.

my $t = t->new_with_options();
$t->options_short_usage($exit_code);

This is automatically fired if the command option "--usage" is passed.

myTool --usage

IMPORT PARAMETERS

The list of parameters supported by MooX::Options.

flavour

Passes extra arguments for Getopt::Long::Descriptive. It is useful if you want to configure Getopt::Long.

use MooX::Options flavour => [qw( pass_through )];

Any flavour is passed to Getopt::Long as a configuration, check the doc to see what is possible.

protect_argv

By default, @ARGV is protected. If you want to do something else on it, use this option and it will change the real @ARGV.

use MooX::Options protect_argv => 0;

skip_options

If you have Role with options and you want to deactivate some of them, you can use this parameter. In that case, the option keyword will just work like an has.

use MooX::Options skip_options => [qw/multi/];

prefer_commandline

By default, arguments passed to new_with_options have a higher priority than the command line options.

This parameter will give the command line an higher priority.

use MooX::Options prefer_commandline => 1;

with_config_from_file

This parameter will load MooX::Options in your module. The config option will be used between the command line and parameters.

myTool :

use MooX::Options with_config_from_file => 1;

In /etc/myTool.json

{"test" : 1}

with_locale_textdomain_oo

This Parameter will load MooX::Locale::TextDomain::OO into your module as well as into MooX::Options::Descriptive::Usage.

No further action is taken, no language is chosen - everything keep in control.

Please read Locale::TextDomain::OO carefully how to enable the desired translation setup accordingly.

usage_string

This parameter is passed to Getopt::Long::Descriptive::describe_options() as the first parameter.

It is a "sprintf"-like string that is used in generating the first line of the usage message. It's a one-line summary of how the command is to be invoked. The default value is "USAGE: %c %o".

%c will be replaced with what Getopt::Long::Descriptive thinks is the program name (it's computed from $0, see "prog_name").

%o will be replaced with a list of the short options, as well as the text "[long options...]" if any have been defined.

The rest of the usage description can be used to summarize what arguments are expected to follow the program's options, and is entirely free-form.

Literal "%" characters will need to be written as "%%", just like with "sprintf".

spacer

This indicate the char to use for spacer. Please only use 1 char otherwize the text will be too long.

The default char is " ".

use MooX::Options space => '+'

Then the "spacer_before" and "spacer_after" will use it for "man" and "help" message.

option 'x' => (is => 'ro', spacer_before => 1, spacer_after => 1);

OPTION PARAMETERS

The keyword option extend the keyword has with specific parameters for the command line.

doc | documentation

Documentation for the command line option.

long_doc

Documentation for the man page. By default the doc parameter will be used.

See also Man parameters to get more examples how to build a nice man page.

required

This attribute indicates that the parameter is mandatory. This attribute is not really used by MooX::Options but ensures that consistent error message will be displayed.

format

Format of the params, same as Getopt::Long::Descriptive.

  • i : integer
  • i@: array of integer
  • s : string
  • s@: array of string
  • f : float value

By default, it's a boolean value.

Take a look of available formats with Getopt::Long::Descriptive.

You need to understand that everything is explicit here. If you use Moose and your attribute has isa => 'Array[Int]', that will not imply the format i@.

format json : special format support

The parameter will be treated like a json string.

option 'hash' => (is => 'ro', json => 1);

You can also use the json format

option 'hash' => (is => 'ro', format => "json");

myTool --hash='{"a":1,"b":2}' # hash = { a => 1, b => 2 }

negatable

It adds the negative version for the option.

option 'verbose' => (is => 'ro', negatable => 1);

myTool --verbose    # verbose = 1
myTool --no-verbose # verbose = 0

The former name of this flag, negativable, is discouraged - since it's not a word.

repeatable

It appends to the "format" the array attribute @.

I advise to add a default value to your attribute to always have an array. Otherwise the default value will be an undefined value.

option foo => (is => 'rw', format => 's@', default => sub { [] });

myTool --foo="abc" --foo="def" # foo = ["abc", "def"]

autosplit

For repeatable option, you can add the autosplit feature with your specific parameters.

option test => (is => 'ro', format => 'i@', default => sub {[]}, autosplit => ',');

myTool --test=1 --test=2 # test = (1, 2)
myTool --test=1,2,3      # test = (1, 2, 3)

It will also handle quoted params with the autosplit.

option testStr => (is => 'ro', format => 's@', default => sub {[]}, autosplit => ',');

myTool --testStr='a,b,"c,d",e,f' # testStr ("a", "b", "c,d", "e", "f")

autorange

For another repeatable option you can add the autorange feature with your specific parameters. This allows you to pass number ranges instead of passing each individual number.

option test => (is => 'ro', format => 'i@', default => sub {[]}, autorange => 1);

myTool --test=1 --test=2 # test = (1, 2)
myTool --test=1,2,3      # test = (1, 2, 3)
myTool --test=1,2,3..6   # test = (1, 2, 3, 4, 5, 6)

It will also handle quoted params like autosplit, and will not rangify them.

option testStr => (is => 'ro', format => 's@', default => sub {[]}, autorange => 1);

myTool --testStr='1,2,"3,a,4",5' # testStr (1, 2, "3,a,4", 5)

autosplit will be set to ',' if undefined. You may set autosplit to a different delimiter than ',' for your group separation, but the range operator '..' cannot be changed.

option testStr => (is => 'ro', format => 's@', default => sub {[]}, autorange => 1, autosplit => '-');

myTool --testStr='1-2-3-5..7' # testStr (1, 2, 3, 5, 6, 7) 

short

Long option can also have short version or aliased.

option 'verbose' => (is => 'ro', short => 'v');

myTool --verbose # verbose = 1
myTool -v        # verbose = 1

option 'account_id' => (is => 'ro', format => 'i', short => 'a|id');

myTool --account_id=1
myTool -a=1
myTool --id=1

You can also use a shorter option without attribute :

option 'account_id' => (is => 'ro', format => 'i');

myTool --acc=1
myTool --account=1

order

Specifies the order of the attribute. If you want to push some attributes at the end of the list. By default all options have an order set to 0, and options are sorted by their names.

option 'at_the_end' => (is => 'ro', order => 999);

hidden

Hide option from doc but still an option you can use on command line.

option 'debug' => (is => 'ro', doc => 'hidden');

Or

option 'debug' => (is => 'ro', hidden => 1);

spacer_before, spacer_after

Add spacer before or after or both the params

option 'myoption' => (is => 'ro', spacer_before => 1, spacer_after => 1);

ADDITIONAL MANUALS

EXTERNAL EXAMPLES

Translation

Translation is now supported.

Use the dzil command to update the pot and merge into the po files.

  • dzil msg-init

    Create a new language po

  • dzil msg-scan

    Scan and generate or update the pot file

  • dzil msg-merge

    Update all languages using the pot file

THANKS

  • sschober

    For implementation and German translation.

THANKS

  • Matt S. Trout (mst) <[email protected]>

    For his patience and advice.

  • Tomas Doran (t0m) <[email protected]>

    To help me release the new version, and using it :)

  • Torsten Raudssus (Getty)

    to use it a lot in DuckDuckGo (go to see MooX module also)

  • Jens Rehsack (REHSACK)

    Use with PkgSrc, and many really good idea (MooX::Cmd, MooX::Options, and more to come I'm sure)

  • All contributors

    For improving and add more feature to MooX::Options

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc MooX::Options

You can also look for information at:

AUTHOR

celogeek <[email protected]>

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by celogeek <[email protected]>.

This software is copyright (c) 2017 by Jens Rehsack.

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

moox-options's People

Contributors

arc avatar arodland avatar avar avatar bobtfish avatar celogeek avatar dsteinbrunner avatar fayland avatar intrigeri avatar kablamo avatar keedi avatar rehsack avatar sergeyromanov avatar sschober avatar szabgab avatar tomlanyon avatar ugexe avatar xaerxess avatar zengargoyle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

moox-options's Issues

Use the value of init_arg to specify the command line name of the option.

Somtimes an option's name on the command line must differ from the name of its attribute. If I were doing this for a normal class, I'd use the init_arg option to has to specify the alternate constructor name.

It would be great if MooX::Options used the value of init_arg as the name of the command line option if it were specified.

BTW, specifying init_arg currently breaks the option, as MooX::Options uses the
attribute name, but that is out of sync with the name that the constructor expects so the option is ignored.

Thanks,
Diab

[BUG] wrong default usage string

According to the documentation "USAGE: %c %o" is the default usage_string. For my program I have configured 2 additional short options -d and -V but they are not shown when I am asking for short (-h) or long help (--help)

USAGE: my_program [-h] [long options ...]

If I am changing the import to this

use MooX::Options usage_string => 'USAGE: %c %o';

I get the expected result

USAGE: my_program [-dhV] [long options ...]

Provide an option to disable required options in parent commands

We use MooX::Options together with MooX::Cmd to build a CLI Application with multiple layers of sub commands. Unfortunately it is not possible to declare options required in intermediate command levels when subcommands do not need these options.

Even the help command fails if one of the higher commands has a required attribute which is not provided additionally with the --help.

It would be nice to have a mean to define the required attribute in a way that it only is parsed when the option is part of the most specific command or if subcommands can disable required options from parent commands.

Example:

cmd has an option 'attr'

cmd subcmd --help
attr is missing 
USAGE: cmd subcmd [-h] [long options...]

Please remove or fix this test t/16-namespace_clean.t

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=942275

Can't locate object method "__" via package "TestNamespaceClean" at /home/paul1/.cpanm/work/1571675833.31763/MooX-Options-4.103/blib/lib/MooX/Options/Role.pm line 352.

Tests were run but no plan was declared and done_testing() was not seen.

Looks like your test exited with 255 just after 1.

t/16-namespace_clean.t ......................
Dubious, test returned 255 (wstat 65280, 0xff00)
All 1 subtests passed

utf8 characters in doc are not displayed correctly when binmode STDERR, ':utf8' is active

I tried to track this down but did not manage to find the reason yet. Maybe we can work this out together:

When I use german umlauts in the doc section of an option and utf-8 binmode is enabled in stderr or globally via PERL_UNICODE=AS, cmd --help produces a broken output which is due to a unicode character interpreted as ASCII I guess.

Example: Berรผcksichtige nur Jobs ... gets Berรƒยผcksichtige nur Jobs...

This problem is already present if I do print $attributes{'doc'} in Options.pm line 195 or so.

The source file is encoded in utf8 and has use utf8 enabled.

Regards,
Christian

[Feature request] Support for --version option.

--version option can be easily implemented in client code. However, it would be nice to have support for --version option directly in MooX::Options because:

  1. --version option is required in almost every script. Even if it is not required, it does not hurt.
  2. If --version option is implemented by the client code, it is shown in the group with other "functional" options, while it should be groped with other "non-functional" options -h, --usage, --help, and --man, because these options (include --version) show some info and exit without doing any other actions.

options with format "s" do not accept "0" as value

Hi,

These work:

perl -E'package Foo; use Moo; use MooX::Options; option start_from => ( is => "ro", format => "s"); package main; my $f = Foo->new_with_options; my $n = $f->start_from; say "increment: ", $n++ for 1..10;' -- --start_from a
perl -E'package Foo; use Moo; use MooX::Options; option start_from => ( is => "ro", format => "s"); package main; my $f = Foo->new_with_options; my $n = $f->start_from; say "increment: ", $n++ for 1..10;' -- --start_from 1
perl -E'package Foo; use Moo; use MooX::Options; option start_from => ( is => "ro", format => "s"); package main; my $f = Foo->new_with_options; my $n = $f->start_from; say "increment: ", $n++ for 1..10;' -- --start_from xyz

This one doesn't work:

perl -E'package Foo; use Moo; use MooX::Options; option start_from => ( is => "ro", format => "s"); package main; my $f = Foo->new_with_options; my $n = $f->start_from; say "increment: ", $n++ for 1..10;' -- --start_from 0

Bug? :)

I'm using MooX::Options 4.008 with Moo 1.005000 and Role::Tiny 1.003003.

No pass_through mode

I'd really like to be able to write several modules with input, output, and processing roles, and do something like:

package Input::Module;
use Moo;
use MooX::Options 'pass_through';
option 'infile',  is => 'ro', required => 1;
option 'informat', is=>'ro', default => 'CSV';

package Output::Module;
use Moo;
use MooX::Options 'pass_through';
option 'outfile',  is => 'ro', default => 'output.csv';
option 'outformat', is=>'ro', default => 'CSV';

package main;
$input = Input::Module->new_with_options;
$output = Output::Module->new_with_options;

Then when I called perl script.pl --outfile foo.json --infile bar --outformat JSON I get something useful.

I think there would be 2 ways of implementing this option:

  • new_with_options ignores anything it doesn't recognise and doesn't modify @ARGV
  • new_with_options ignores anything it doesn't recognise and removes anything it does from @ARGV

Getopt::Long does the second.

What do you think?

3.90 fails to install when Mouse::Role isn't installed

I've created this issue here because I don't want to register at your personal redmine installation.

[ahartmai@ahartmai-nb:~$ ]$ cpanp i MooX::Options
Installing MooX::Options (3.90)
Running [/usr/bin/make test]...
PERL_DL_NONLAZY=1 /home/ahartmai/perl5/perlbrew/perls/18/bin/perl "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
Can't locate Mouse/Role.pm in @INC (you may need to install the Mouse::Role module) (@INC contains: lib /home/ahartmai/.cpanplus/5.18.1/build/Mo-0.36/blib/lib /home/ahartmai/.cpanplus/5.18.1/build/Mo-0.36/blib/arch /home/ahartmai/perl5/perlbrew/perls/18/lib/site_perl/5.18.1/x86_64-linux-thread-multi /home/ahartmai/perl5/perlbrew/perls/18/lib/site_perl/5.18.1 /home/ahartmai/perl5/perlbrew/perls/18/lib/5.18.1/x86_64-linux-thread-multi /home/ahartmai/perl5/perlbrew/perls/18/lib/5.18.1 .) at lib/Mo/Mouse.pm line 3.
BEGIN failed--compilation aborted at lib/Mo/Mouse.pm line 3.
Compilation failed in require at -e line 1.

#   Failed test 'Mo::Mouse loaded ok'
#   at t/00-compile.t line 62.
#                   ''
#     doesn't match '(?^s:^\s*Mo::Mouse ok)'
# Looks like you failed 1 test of 19.
t/00-compile.t ................ 
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/19 subtests 
# 
# 
# Generated by Dist::Zilla::Plugin::ReportVersions::Tiny v1.08
# perl: 5.018001 (wanted v5.6.0) on linux from /home/ahartmai/perl5/perlbrew/perls/18/bin/perl
# 
# Class::XSAccessor                             => 1.18       (want any version)
# ExtUtils::MakeMaker                           => 6.8        (want 6.30)   
# IO::All                                       => 0.50       (want any version)
# Moose                                         => 2.1005     (want any version)
# Mouse                                         => module not found. (want any version)
# Test::CPAN::Meta                              => 0.23       (want any version)
# Test::More                                    => 0.99       (want 0.96)   
# Test::Pod                                     => 1.48       (want 1.41)   
# version                                       => 0.9904     (want 0.9901) 
# 
# Thanks for using my code.  I hope it works for you.
# If not, please try and include this output in the bug report.
# That will help me reproduce the issue and solve your problem.
# 
t/000-report-versions-tiny.t .. ok
t/author-pod-spell.t .......... skipped: these tests are for testing by the author
t/build.t ..................... ok
t/builder.t ................... ok
t/chain.t ..................... ok
t/coerce.t .................... ok
t/combined.t .................. ok
t/default.t ................... ok
t/extends.t ................... ok
t/importer.t .................. ok
t/is.t ........................ ok
t/lazy-nonlazy.t .............. ok
t/main_sub.t .................. ok
t/Moose.t ..................... ok
t/Mouse.t ..................... skipped: Mouse is needed
t/object.t .................... ok
t/option.t .................... ok
t/release-correct-version.t ... skipped: these tests are for release candidate testing
t/release-distmeta.t .......... skipped: these tests are for release candidate testing
t/release-eol.t ............... skipped: these tests are for release candidate testing
t/release-no-tabs.t ........... skipped: these tests are for release candidate testing
t/release-pod-syntax.t ........ skipped: these tests are for release candidate testing
t/release-test-version.t ...... skipped: these tests are for release candidate testing
t/required.t .................. ok
t/strict.t .................... ok
t/test.t ...................... ok
t/xs.t ........................ ok

Test Summary Report
-------------------
t/00-compile.t              (Wstat: 256 Tests: 19 Failed: 1)
  Failed test:  5
  Non-zero exit status: 1
Files=28, Tests=171,  2 wallclock secs ( 0.11 usr  0.03 sys +  1.52 cusr  0.23 csys =  1.89 CPU)
Result: FAIL
Failed 1/28 test programs. 1/171 subtests failed.
make: *** [test_dynamic] Error 255

The tests for 'Mo' failed. Would you like me to proceed anyway or should we abort?

Make -h look more compact like `git add -h`

I'd like my usage output to look more compact like git:

โšก git add -h
usage: git add [options] [--] <filepattern>...

    -n, --dry-run         dry run
    -v, --verbose         be verbose

    -i, --interactive     interactive picking
    -p, --patch           select hunks interactively
    -e, --edit            edit current diff and apply
    -f, --force           allow adding otherwise ignored files
    -u, --update          update tracked files
    -N, --intent-to-add   record only the fact that the path will be added later
    -A, --all             add changes from all tracked and untracked files
    --refresh             don't add, only refresh the index
    --ignore-errors       just skip files which cannot be added because of errors
    --ignore-missing      check if - even missing - files are ignored in dry run

I'd prefer to change the default look. But another idea is to make it an optional feature which could work like this:

package App::Cmd::Boop;
use MooX::Cmd;
use MooX::Option compact_usage => 1;

Are you interested in a pull request like this?

Is perl 5.10.0 really required?

use feature 'state' appears in a .pm, but then state is never used. And it looks like say is only used in a few tests, which could easily be removed. Is there another reason for requiring 5.10?

no support for UTF-8 doc strings in man mode?

I use MooX::Options 4.009. When I try to use a non-ascii character in a doc string like so:

#!/usr/bin/env perl
package MyCmd;

use Modern::Perl '2014';
use Moo;
use MooX::Options;

option 'opt1' => ( is => 'ro', doc => 'Schรถne GrรผรŸe!' );

package main;
my $opt = MyCmd->new_with_options;

When I invoke --help all is well:

$ ./mycmd.pl --help
USAGE: mycmd.pl [-h] [long options...]

    --opt1:
        Schรถne GrรผรŸe!

    --usage:
        show a short help message

    -h --help:
        show a help message

    --man:
        show the manual

But, when I try `--man`` I get:

NAME
    mycmd.pl

SYNOPSIS
    mycmd.pl [-h] [long options ...]

OPTIONS
    --opt1:
        Sch<F6>ne Gr<FC><DF>e!

    --usage:
        show a short help message

    -h --help:
        show a help message

    --man:
        show the manual

POD ERRORS
    Hey! The above document had some coding errors, which are explained
    below:

    Around line 15:
        Non-ASCII character seen before =encoding in 'Sch<F6>ne'. Assuming UTF-8

(END)

I investigated this a bit and found that this has several reasons:

  1. Path::Class::File is generating /tmp/.../help.pod as an ISO8859-1 file (for me?):

    $ file /tmp/XoCMJyft1x/help.pod 
    /tmp/XoCMJyft1x/help.pod: Perl POD document, ISO-8859 text
    
  2. help.pod does not contain =encoding utf-8

I've put together a quick fix in pull request #22.

Unintuitive behaviour of options taking a parameter when a default value is given

In the following code, the name option takes a string parameter and also has a default value 'UNKNOWN':

# test.pl
use strict;
use warnings;

package MyApp;

use Moo;
use MooX::Cmd;
use MooX::Options;

option name => (
    is      => 'ro',
    format  => 's',
    default => 'UNKNOWN',
);

sub execute {
    my ($self, $args) = @_;

    print "Name: " . $self->name . "\n";
}

1;

package main;

MyApp->new_with_cmd;

When the code is run as perl test.pl --name (no name passed), the script runs successfully and sets name to the default value. The output is:

Name: UNKNOWN

Ideally I'd expect an error to be thrown since --name is not provided with a parameter.

Fails tests without '.' in @INC

On 5.25.10 with -Ddefault_inc_excludes_dot

Building and testing MooX-Options-4.023
Building MooX-Options
Can't locate t/Test.pm in @INC (you may need to install the t::Test module) (@INC contains: /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/around_options_usage.t line 10.
BEGIN failed--compilation aborted at t/around_options_usage.t line 10.
t/around_options_usage.t ................. 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
Can't locate t/Test.pm in @INC (you may need to install the t::Test module) (@INC contains: /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/autosplit_warning_on_required_param.t line 10.
BEGIN failed--compilation aborted at t/autosplit_warning_on_required_param.t line 10.
t/autosplit_warning_on_required_param.t .. 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
Can't locate t/Test.pm in @INC (you may need to install the t::Test module) (@INC contains: /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/hidden.t line 10.
BEGIN failed--compilation aborted at t/hidden.t line 10.
t/hidden.t ............................... 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
# Testing with Perl 5.025010, /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/bin/perl5.25.10
Can't locate t/Test.pm in @INC (you may need to install the t::Test module) (@INC contains: /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/isa_check.t line 10.
BEGIN failed--compilation aborted at t/isa_check.t line 10.
t/isa_check.t ............................ 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
Can't locate t/Test.pm in @INC (you may need to install the t::Test module) (@INC contains: /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/mo.t line 11.
BEGIN failed--compilation aborted at t/mo.t line 11.
t/mo.t ................................... 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
t/author-critic.t ........................ skipped: these tests are for testing by the author
Can't locate t/Test.pm in @INC (you may need to install the t::Test module) (@INC contains: /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/moose.t line 11.
BEGIN failed--compilation aborted at t/moose.t line 11.
t/moose.t ................................ 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
Can't locate t/Test.pm in @INC (you may need to install the t::Test module) (@INC contains: /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/moox-cmd.t line 11.
BEGIN failed--compilation aborted at t/moox-cmd.t line 11.
t/moox-cmd.t ............................. 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
Can't locate t/Test.pm in @INC (you may need to install the t::Test module) (@INC contains: /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/multi_role.t line 10.
BEGIN failed--compilation aborted at t/multi_role.t line 10.
t/multi_role.t ........................... 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
#     Capture::Tiny version is 0.46
#     Carp version is 1.42
#     Data::Record version is 0.02
#     English version is 1.10
#     File::Spec version is 3.66
#     FindBin version is 1.51
#     Getopt::Long version is 2.49
Can't locate t/Test.pm in @INC (you may need to install the t::Test module) (@INC contains: /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/multiple-split-options.t line 10.
BEGIN failed--compilation aborted at t/multiple-split-options.t line 10.
t/multiple-split-options.t ............... 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
Can't locate t/Test.pm in @INC (you may need to install the t::Test module) (@INC contains: /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/namespace_clean.t line 10.
BEGIN failed--compilation aborted at t/namespace_clean.t line 10.
t/namespace_clean.t ...................... 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
Can't locate t/Test.pm in @INC (you may need to install the t::Test module) (@INC contains: /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/no_option.t line 10.
BEGIN failed--compilation aborted at t/no_option.t line 10.
t/no_option.t ............................ 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
Can't locate t/Test.pm in @INC (you may need to install the t::Test module) (@INC contains: /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/option-of-option.t line 10.
BEGIN failed--compilation aborted at t/option-of-option.t line 10.
t/option-of-option.t ..................... 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
#     Getopt::Long::Descriptive version is 0.100
#     IO::Handle version is 1.36
#     IPC::Open3 version is 1.20
#     Import::Into version is 1.002005
#     JSON::MaybeXS version is 1.003008
Can't locate t/Test.pm in @INC (you may need to install the t::Test module) (@INC contains: /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/order.t line 10.
BEGIN failed--compilation aborted at t/order.t line 10.
t/order.t ................................ 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
Can't locate t/Test.pm in @INC (you may need to install the t::Test module) (@INC contains: /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/pod.t line 11.
BEGIN failed--compilation aborted at t/pod.t line 11.
t/pod.t .................................. 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
#     Locale::TextDomain version is 1.26
Can't locate t/Test.pm in @INC (you may need to install the t::Test module) (@INC contains: /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/moo.t line 11.
BEGIN failed--compilation aborted at t/moo.t line 11.
t/moo.t .................................. 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
t/release-kwalitee.t ..................... skipped: these tests are for release candidate testing
t/release-pod-coverage.t ................. skipped: these tests are for release candidate testing
Can't locate t/Test.pm in @INC (you may need to install the t::Test module) (@INC contains: /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/role.t line 10.
BEGIN failed--compilation aborted at t/role.t line 10.
t/role.t ................................. 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
Can't locate t/Test.pm in @INC (you may need to install the t::Test module) (@INC contains: /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/spacer.t line 10.
BEGIN failed--compilation aborted at t/spacer.t line 10.
t/spacer.t ............................... 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
#     Module::Build version is 0.422
#     Module::Metadata version is 1.000033
#     Moo version is 2.003
#     MooX::ConfigFromFile version is 0.007
#     POSIX version is 1.76
#     Path::Class version is 0.37
Can't locate t/Test.pm in @INC (you may need to install the t::Test module) (@INC contains: /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/string_with_zero_value.t line 10.
BEGIN failed--compilation aborted at t/string_with_zero_value.t line 10.
t/string_with_zero_value.t ............... 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
Can't locate t/Test.pm in @INC (you may need to install the t::Test module) (@INC contains: /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/usage_string.t line 10.
BEGIN failed--compilation aborted at t/usage_string.t line 10.
t/usage_string.t ......................... 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
#     Pod::Usage version is 1.69
#     Regexp::Common version is 2016060801
Can't locate t/Test.pm in @INC (you may need to install the t::Test module) (@INC contains: /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/check_target_methods.t line 10.
BEGIN failed--compilation aborted at t/check_target_methods.t line 10.
t/check_target_methods.t ................. 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
Can't locate t/Test.pm in @INC (you may need to install the t::Test module) (@INC contains: /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/doc-utf8.t line 10.
BEGIN failed--compilation aborted at t/doc-utf8.t line 10.
t/doc-utf8.t ............................. 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
Can't locate t/Test.pm in @INC (you may need to install the t::Test module) (@INC contains: /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/doc.t line 10.
BEGIN failed--compilation aborted at t/doc.t line 10.
t/doc.t .................................. 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
#     Role::Tiny::With version is 2.000005
Can't locate t/Test.pm in @INC (you may need to install the t::Test module) (@INC contains: /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/with_config.t line 10.
BEGIN failed--compilation aborted at t/with_config.t line 10.
t/with_config.t .......................... 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
t/release-unused-vars.t .................. skipped: these tests are for release candidate testing
#     Scalar::Util version is 1.4602
#     Term::Size::Any version is 0.002
#     Test::More version is 1.302073
#     Test::Requires version is 0.10
Can't locate t/Test.pm in @INC (you may need to install the t::Test module) (@INC contains: /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/failure.t line 10.
BEGIN failed--compilation aborted at t/failure.t line 10.
t/failure.t .............................. 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
#     Test::Trap version is 0.3.2
Can't locate t/Test.pm in @INC (you may need to install the t::Test module) (@INC contains: /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/lib /home/kent/.cpanm/work/1488869598.17922/MooX-Options-4.023/blib/arch /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/site_perl/5.25.10 /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10/x86_64-linux /home/kent/perl5/perlbrew/perls/5.25.10-nossp-sdbm-nopmc-nodot/lib/5.25.10) at t/flavour.t line 11.
BEGIN failed--compilation aborted at t/flavour.t line 11.
t/flavour.t .............................. 
Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
#     Text::LineFold version is 2012.04
#     Try::Tiny version is 0.28
#     lib version is 0.64
#     namespace::clean version is 0.27
#     overload version is 1.28
#     parent version is 0.236
#     strict version is 1.11
#     warnings version is 1.37
t/000-report-versions.t .................. ok
t/00-compile.t ........................... ok

Test Summary Report
-------------------
t/around_options_usage.t               (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t/autosplit_warning_on_required_param.t (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t/hidden.t                             (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t/isa_check.t                          (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t/mo.t                                 (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t/moose.t                              (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t/moox-cmd.t                           (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t/multi_role.t                         (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t/multiple-split-options.t             (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t/namespace_clean.t                    (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t/no_option.t                          (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t/option-of-option.t                   (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t/order.t                              (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t/pod.t                                (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t/moo.t                                (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t/role.t                               (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t/spacer.t                             (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t/string_with_zero_value.t             (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t/usage_string.t                       (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t/check_target_methods.t               (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t/doc-utf8.t                           (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t/doc.t                                (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t/with_config.t                        (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t/failure.t                            (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
t/flavour.t                            (Wstat: 512 Tests: 0 Failed: 0)
  Non-zero exit status: 2
  Parse errors: No plan found in TAP output
Files=31, Tests=39,  1 wallclock secs ( 0.10 usr  0.06 sys +  0.98 cusr  0.26 csys =  1.40 CPU)
Result: FAIL
Failed 25/31 test programs. 0/39 subtests failed.

Add the ability to hide an option

Can you please add an ability to hide an option from the help message?
Looks like this can be accomplished with Getopt::Long::Descriptive if you use the hidden attribute.

I can see 2 ways to do this,
one create a hidden attribute for the option,
another one would be to not show any private options. i.e any options that start with an _

Thanks,
Eddie

Short version is not showed by the --help

The code:

package Test;

use Moo;
use MooX::Options;

option 'account_id' => (is => 'ro', format => 'i', short => 'a|id');

1;

package main;

Test->new_with_options;

The result:

./test --help
USAGE: test [-h] [long options ...]

    --account_id: Int
        no doc for account_id

                                                                            
    
    --usage:
        show a short help message

    -h:
        show a compact help message

    --help:
        show a long help message

    --man:
        show the manual

Best regards,
Emanuele

Error while prompting for user input

I'm using MooX::Options and I want to prompt for user input if something isn't passed in. When I prompt for input I'm getting this error:

prompt(): Can't open *ARGV: No such file or directory at ./iam-role-setup.pl line 56.

I'm using IO::Prompter for input. I tried a few other options/modules and they all have similar issues.

Here is an example script (test.pl):

#! /usr/bin/env perl

use Moo;
use MooX::Options;
use IO::Prompter;
use feature 'say';

option "verbose" => (
    is => 'ro',
    short => 'v',
    doc => 'Turn on verbose logging',
    default => 0,
);

option "username" => (
    is => 'lazy',
    format => 's',
    short => 'u',
    doc => "Your username",
);

sub _build_username {
    my ($self) = @_;
    prompt -v, "Enter your username";
}

sub run {
    my ($self) = @_;
    say $self->verbose;
    say $self->username;
}
main->new_with_options->run;

Try calling test.pl -v

Classes that use roles that `use MooX::Options;` must `use MooX::Options;` even if they themselves don't have `options` declarations

A minimal example:

~ $ cat optional.pm
package optional;
use strict;
use warnings;
use Moo::Role;
use MooX::Options;

option 'foo' => (doc => 'A silly option',
                 format => 's',
                 is => 'ro',
                 required => 1);

1;
~ $ cat mooxtest.pm
package test;

use Moo;
with 'optional';

sub frob {
    my ($self) = @_;
    printf "We love %s\n", $self->foo;
}
~ $ perl mooxtest.pm
Can't apply optional to test - missing _options_data, _options_config at /home/utils/perl5/perlbrew/perls/5.24.0-001/lib/site_perl/5.24.0/Moo/Role.pm line 287.

If you add use MooX::Options; to mooxtest.pm just before the with 'optional', it compiles.

Using Type::Tiny in isa does not show error message

When using Type::Tiny in the isa, field of the option, the type::tiny error no error message gets displayed to the screen, just that the program died @ the line number of new_with_options. It would be nice to display the type tiny error message.

Number of minor inefficiences

Since this is a module to be used in CLI scripts I figured you'd be interested in some simple ways to cut down the startup time:

You load MRO::Compat, but you do not use it anywhere afterwards - you can safely remove it.
You also load the entirety of Regexp::Common for a single use of =~ /['"`]/
Carp is rather heavy these days - requiring it dynamically at the two spots where you use croak() will make your startup more lightweight
You can similarly avoid Data::Record by recording qr()'s in %has_to_split

Also there is an incosistency - your current Regexp::Common use matches /['"`]/, however you only sanitise ' and " here: https://metacpan.org/source/CELOGEEK/MooX-Options-3.1/lib/MooX/Options/Role.pm#L71

HTH

new_with_options and short options

Upgrading to version 4.100 I got a failure with short options, c.f. https://rt.cpan.org/Ticket/Display.html?id=122395 .
Not sure this come from my code, though: I isolated a potential issue with new_with_options, i.e.:

perl -MMoo -MMooX::Options -e 'option interactive => (short => "i"); option include => (short => "Z"); __PACKAGE__->new_with_options();'

raises:

There is already an abbreviation 'i' - can't use it to shorten 'interactive' at -e line 1.

Can you please tell me if I have to adapt my code and how ? Thanks!

Help does not display short/aliases

I have the following script:

use strict;

use MyClass;

my $s = MyClass->new_with_options;

And MyClass.pm:

use strict;

package MyClass;

use Moo;
use MooX::Options;

option 'account_id' => (is => 'ro', format => 'i', short => 'a|id', doc => 'doc');

option 'account_id' => (is => 'ro', format => 'i', short => 'a', doc => 'doc');

1;

The help message in this case is what I expected:

perl p.pl -h
USAGE: p.pl [-ah] [long options...]

-a --account_id: Int
    doc

...

However if I activate the second option line in the script instead of the first:

option 'account_id' => (is => 'ro', format => 'i', short => 'a|id', doc => 'doc');

option 'account_id' => (is => 'ro', format => 'i', short => 'a', doc => 'doc');

The help message has no info about the aliases at all:

perl p.pl -h
USAGE: p.pl [-ah] [long options...]

--account_id: Int
    doc

I expected something like:

-a --is --account_id: Int
doc

_get_line_fold is not returning the correct number of culumns

When I run a command with --help, it wraps at 80 columns.

When I run

perl -MTerm::Size::Any -E 'say  [ Term::Size::Any::chars() ]->[0];'
141

it returns the correct number of columns. Likewise, running the --help with

TEST_FORCE_COLUMN_SIZE=141 

also works correctly. But by default it's not working.

It seems that the eval syntax doesn't work:

sub _get_line_fold {
    my $columns = $ENV{TEST_FORCE_COLUMN_SIZE}
        || eval {
        use_module("Term::Size::Any");
        [ Term::Size::Any::chars() ]->[0];
        } || 80;
 
    return Text::LineFold->new( ColMax => $columns - 4 );
}

Running

perl -MModule::Runtime=use_module \\
   -E 'my $columns =  eval { use_module("Term::Size::Any"); [ Term::Size::Any::chars() ]->[0]; }; say $columns; '

displays nothing

t/basic.t dies with latest Moo

Last test is doing a fairly fragile regex on an error message which appears to have changed in a recent version of Moo.

Annoying empty lines between user options and standard options

The code:

package Test;

use Moo;
use MooX::Options;

option 'account_id' => (is => 'ro', format => 'i', short => 'a|id');

1;

package main;

Test->new_with_options;

The result:

./test --help
USAGE: test [-h] [long options ...]

    --account_id: Int
        no doc for account_id

                                                                            
    
    --usage:
        show a short help message

    -h:
        show a compact help message

    --help:
        show a long help message

    --man:
        show the manual

I'm sorry for the duplicate test case (see #71), but they are two different things.

Best regards,
Emanuele

Tests fail with Moo 2.002002

My smokers report the following new failure:

#   Failed test 'stdout ok'
#   at t/autosplit_warning_on_required_param.t line 35.
#                   'Missing is missing
# USAGE: autosplit_warning_on_required_param.t [-h] [long options...]
# 
#     --treq=[Strings]  this is mandatory
#                                                                         
#     --usage           show a short help message
#     -h                show a compact help message
#     --help            show a long help message
#     --man             show the manual
# 
# '
#     doesn't match '(?^:treq is missing)'
# Looks like you failed 1 test of 2.
t/autosplit_warning_on_required_param.t .. 
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/2 subtests 

This seems to be caused by the most recent Moo version. Statistical analysis (negative theta is bad):

****************************************************************
Regression 'mod:Moo'
****************************************************************
Name                   Theta          StdErr     T-stat
[0='const']           1.0000          0.0000    14603697401575358.00
[1='eq_2.000001']             0.0000          0.0000       4.21
[2='eq_2.000002']             0.0000          0.0000       5.57
[3='eq_2.001001']             0.0000          0.0000       4.75
[4='eq_2.002002']            -1.0000          0.0000    -14251749359515692.00

R^2= 1.000, N= 135, K= 5
****************************************************************

[QUESTION] How to setup verbose as an "incremental" option?

GetOpt::Long offers this

my $verbose = '';                     # option variable with default value (false)
GetOptions ('verbose+' => \$verbose); # Using --verbose on the command line will increment the value of $verbose

How can I do such a setup with MooX::Options?

perl 5.10

Is there any particular reason the module to require perl 5.10? I've only spotted one defined-or operator and Moo itself doesn't require perl 5.10?

Need ability to add text to the usage string

I have a script that will accept a list of directories at the end of the options. I need a way to be able to specify that in the usage string.

Another thing would be nice would be the option to place all remaining @argv not used in a attribute, and have a doc message for that

--help produces too many empty lines

Consider an example:

#!/usr/bin/perl
{
    package MyOpt;
    use Moo;
    use MooX::Options;
    option 'one' => (
        is  => 'ro',
    );
    option 'two' => (
        is  => 'ro',
    );
}
my $a = MyOpt->new_with_options();

And its output:

$ perl ./moo-options.pl --help
USAGE: moo-options.pl [-h] [long options...]

    --one:
        no doc for one


    --two:
        no doc for two





    --usage:
        show a short help message


    -h:
        show a compact help message


    --help:
        show a long help message


    --man:
        show the manual

Every option is separated from others with two empty lines. Option groups are separated by 5(!) empty lines. It seems one empty line between options and two between groups is enough.

short hash options don't work

I'm defining an option define with short form D, format s%. Unfortunately the short version is broken.

Here's the test code:

package myOptions;

use Moo;
use MooX::Options;

option define => (
    short   => 'D',
    is      => 'ro',
    format  => 's%',
    default => sub { {} },
);

package main;

my $q = myOptions->new_with_options;

use Data::Dumper;

print Dumper $q->define;

And here's what happens if I use -D:

% perl topt -D a=b
Option D requires an argument
USAGE: topt [-Dh] [long options...]
[...]

% perl topt -Da=b
Option D, key "a", requires a value
Unknown option: a
[...]

Using the long form works.

Thanks,
Diab

Tests fail with non-English locale (MooX-Options-4.019)

With a German locale:

#   Failed test 'Usage ok'
#   at t/around_options_usage.t line 54.
#                   'Aufruf: around_options_usage.t [-ht] [long options...]'
#     doesn't match '(?^:^USAGE)'

#   Failed test 'Usage ok'
#   at t/around_options_usage.t line 60.
#                   'Aufruf: around_options_usage.t [-ht] [long options...]'
#     doesn't match '(?^:^USAGE)'
# Looks like you failed 2 tests of 6.
t/around_options_usage.t ................. 
...
#   Failed test 'negativable and format are incompatible'
#   at t/failure.t line 37.
#                   'Ung"ultige Formatspezifikation. Negierbare Parameter sind mit Bool'schen Werten nicht einsetzbar. at (eval 6) line 5.
# '
#     doesn't match '(?^x:^Negativable\sparams\sis\snot\susable\swith\snon\sboolean\svalue,\sdon't\spass\sformat\sto\suse\sit\s\!)'

... (etc.) ...

Actual $@ being swallowed in MooX::Options::Role

Hi,

I don't have a simple test case, but got bitten by this and I had to patch the local installation of this file MooX/Options/Role.pm to be able to see the actual error.

Here is a demonstration of the problem:

$ perl -wle '$@ = q{isa check for "foo" failed:  at (eval 890) line 416.}; if ( $@ =~ /^isa\scheck.*?failed:\s/x ) { print STDERR substr( $@, index( $@, q{:} ) + 2 ) }'
 at (eval 890) line 416.

So, the actual error isa check for "foo" failed: is dropped and all that is displayed is the meaningless at (eval 890) line 416. portion.

print STDERR substr( $@, index( $@, ':' ) + 2 );

I'm not sure how you want to tackle this, but I'd like to see the unmodified $@ personally.

MooX::Options doesn't support the increment getopt

Please add an inc/increment option, it is currently missing.

For completeness description of what increment does:

  • The option does not take an argument and will be incremented by 1 every time it appears on the command line. E.g. "more+", when used with --more --more --more, will increment the value three times, resulting in a value of 3 (provided it was 0 or undefined at first).

The + specifier is ignored if the option destination is not a scalar.

Can't modify $usage_str to add a command line argument

So options are nicely handled. But not bare arguments. For example, I can't have a usage string like:

USAGE: cmd subcmd FILE DIR [-h] [long options...]

Where FILE can be any filename and DIR can be any DIR. Would you accept a pr for this? I am thinking it would be configured like this:

use MooX::Options 
    description => '...', 
    args => 'FILE DIR';

Documentation could be extended for 'repeatables'

Where an attribute is repeatable (s@ and i@) it would be helpful if the documentation suggested that default => sub {[]} be used on the 'option =>' so that programatically, push can be used on it (suggest under 'format' or 'repeatable').

option bar => ( is => rw, default => sub {[]} );

push @{ $foo->bar }, 'baz'; # now works as expected rather than returning "Can't use an undefined value as an ARRAY reference"

MooX::Options::Role _options_fix_argv strips leading and trailing quotes from parameter values

This bit of code in the _options_fix_argv routine of MooX::Options::Role strips leading and trailing quotes:

#remove the quoted if exist to chain
$_[0] =~ s/^['"]|['"]$//gx;

This is a problem when you want to preserve those quotes. A small example:

#!/usr/bin/env perl

package Test;

use Moo;
use MooX::Options;

option test => (
    is         => 'ro',
    short      => 't',
    format     => 's',
);  

1;

package main;

my $t = Test->new_with_options;
print $t->test."\n";

Run the above:

./test.pl -t "This is 'a test'"
This is 'a test

When I would expect to see

This is 'a test'

as its output.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.