I have made "MooX::Option". This add "option" and "new_with_options" keyword to your module.
You will be available to easily create a command line tools in Modern Perl.
Example :
package t; use Moo; use MooX::Option; option 'verbose' => (is => 'ro', repeatable => 1, short => 'v', doc => 'my verbose option'); option 'str' => (is => 'ro', format => 's'); 1; my $params = t->new_with_options; my $params_with_override = t->new_with_options(str => 'overrided');
They is more, for example you can use it with 'Moose' :
package t; use Moose; use MooX::Option filter => 'Moose'; option 'verbose' => (is => 'ro', repeatable => 1, short => 'v', doc => 'my verbose option'); option 'str' => (is => 'ro', format => 's'); 1; my $params = t->new_with_options; my $params_with_override = t->new_with_options(str => 'overrided');
package t; use Moo; use MooX::Option option_method_name => 'getopt'; getopt 'verbose' => (is => 'ro', repeatable => 1, short => 'v', doc => 'my verbose option'); getopt 'str' => (is => 'ro', format => 's'); 1; my $params = t->new_with_options;
package t; use Moo; use MooX::Option creation_method => 'new_with_options', creation_method_name => 'new_from_env'; getopt 'verbose' => (is => 'ro', repeatable => 1, short => 'v', doc => 'my verbose option'); getopt 'str' => (is => 'ro', format => 's'); 1; my $params = t->new_from_env;
Fill free to comment and purpose idea.
Here the links :
Celogeek