@@ -17,7 +17,7 @@ my %module_build_args = (
"celogeek <me\@celogeek.com>"
],
"dist_name" => "MooX-Options",
- "dist_version" => "4.003",
+ "dist_version" => "4.008",
"license" => "perl",
"module_name" => "MooX::Options",
"recommends" => {},
@@ -1,3 +1,20 @@
+4.008 2014-02-01 09:49:36 GMT
+ * Bug #405 : fix typo in pod (Celogeek San)
+
+4.007 2014-01-17 15:57:22 GMT
+ * Bug #403 : fix pod (Grzegorz Rożniecki)
+
+4.006 2013-12-18 14:31:42 GMT
+ * Bug #388 : Short option not properly fixed (fix_argv) (Celogeek San)
+
+4.005 2013-12-16 12:44:02 GMT
+ * Bug #383: autosplit should handle all variance of "-" and "_"
+ Fix tests (reused vars)
+
+4.004 2013-12-14 13:00:38 GMT
+ * Bug #383: autosplit should handle all variance of "-" and "_"
+ implement a proper fix_argv method
+
4.003 2013-12-01 00:40:22 GMT
* Feature #370 : Add usage, only the usage row with all the long options (Celogeek San)
@@ -87,10 +87,10 @@
"web" : "https://github.com/celogeek/MooX-Options"
}
},
- "version" : "4.003",
+ "version" : "4.008",
"x_Dist_Zilla" : {
"perl" : {
- "version" : "5.018001"
+ "version" : "5.018002"
},
"plugins" : [
{
@@ -192,7 +192,7 @@
}
},
"name" : "@GRS/Test::Compile",
- "version" : "2.037"
+ "version" : "2.039"
},
{
"class" : "Dist::Zilla::Plugin::Test::UnusedVars",
@@ -237,11 +237,93 @@
"finder" : [
":InstallModules",
":ExecFiles"
+ ],
+ "plugins" : [
+ {
+ "class" : "Pod::Weaver::Plugin::EnsurePod5",
+ "name" : "@CorePrep/EnsurePod5",
+ "version" : "4.004"
+ },
+ {
+ "class" : "Pod::Weaver::Plugin::H1Nester",
+ "name" : "@CorePrep/H1Nester",
+ "version" : "4.004"
+ },
+ {
+ "class" : "Pod::Weaver::Section::Name",
+ "name" : "@Default/Name",
+ "version" : "4.004"
+ },
+ {
+ "class" : "Pod::Weaver::Section::Version",
+ "name" : "@Default/Version",
+ "version" : "4.004"
+ },
+ {
+ "class" : "Pod::Weaver::Section::Region",
+ "name" : "@Default/prelude",
+ "version" : "4.004"
+ },
+ {
+ "class" : "Pod::Weaver::Section::Generic",
+ "name" : "DESCRIPTION",
+ "version" : "4.004"
+ },
+ {
+ "class" : "Pod::Weaver::Section::Generic",
+ "name" : "SYNOPSIS",
+ "version" : "4.004"
+ },
+ {
+ "class" : "Pod::Weaver::Section::Generic",
+ "name" : "OVERVIEW",
+ "version" : "4.004"
+ },
+ {
+ "class" : "Pod::Weaver::Section::Collect",
+ "name" : "ATTRIBUTES",
+ "version" : "4.004"
+ },
+ {
+ "class" : "Pod::Weaver::Section::Collect",
+ "name" : "METHODS",
+ "version" : "4.004"
+ },
+ {
+ "class" : "Pod::Weaver::Section::Collect",
+ "name" : "FUNCTIONS",
+ "version" : "4.004"
+ },
+ {
+ "class" : "Pod::Weaver::Section::Leftovers",
+ "name" : "@Default/Leftovers",
+ "version" : "4.004"
+ },
+ {
+ "class" : "Pod::Weaver::Section::Region",
+ "name" : "@Default/postlude",
+ "version" : "4.004"
+ },
+ {
+ "class" : "Pod::Weaver::Section::Bugs",
+ "name" : "@Default/Bugs",
+ "version" : "4.004"
+ },
+ {
+ "class" : "Pod::Weaver::Section::Authors",
+ "name" : "@Default/Authors",
+ "version" : "4.004"
+ },
+ {
+ "class" : "Pod::Weaver::Section::Legal",
+ "name" : "@Default/Legal",
+ "version" : "4.004"
+ }
]
}
},
"name" : "@GRS/PodWeaver",
- "version" : "3.102000"
+ "version" : "4.002"
},
{
"class" : "Dist::Zilla::Plugin::PerlTidy",
@@ -54,10 +54,10 @@ resources:
bugtracker: https://github.com/celogeek/MooX-Options/issues
homepage: https://tasks.celogeek.com/projects/perl-modules-moox-options
repository: https://github.com/celogeek/MooX-Options.git
-version: 4.003
+version: 4.008
x_Dist_Zilla:
perl:
- version: 5.018001
+ version: 5.018002
plugins:
-
class: Dist::Zilla::Plugin::GatherDir
@@ -137,7 +137,7 @@ x_Dist_Zilla:
script_finder:
- ':ExecFiles'
name: '@GRS/Test::Compile'
- version: 2.037
+ version: 2.039
-
class: Dist::Zilla::Plugin::Test::UnusedVars
name: '@GRS/Test::UnusedVars'
@@ -174,8 +174,73 @@ x_Dist_Zilla:
finder:
- ':InstallModules'
- ':ExecFiles'
+ plugins:
+ -
+ class: Pod::Weaver::Plugin::EnsurePod5
+ name: '@CorePrep/EnsurePod5'
+ version: 4.004
+ -
+ class: Pod::Weaver::Plugin::H1Nester
+ name: '@CorePrep/H1Nester'
+ version: 4.004
+ -
+ class: Pod::Weaver::Section::Name
+ name: '@Default/Name'
+ version: 4.004
+ -
+ class: Pod::Weaver::Section::Version
+ name: '@Default/Version'
+ version: 4.004
+ -
+ class: Pod::Weaver::Section::Region
+ name: '@Default/prelude'
+ version: 4.004
+ -
+ class: Pod::Weaver::Section::Generic
+ name: DESCRIPTION
+ version: 4.004
+ -
+ class: Pod::Weaver::Section::Generic
+ name: SYNOPSIS
+ version: 4.004
+ -
+ class: Pod::Weaver::Section::Generic
+ name: OVERVIEW
+ version: 4.004
+ -
+ class: Pod::Weaver::Section::Collect
+ name: ATTRIBUTES
+ version: 4.004
+ -
+ class: Pod::Weaver::Section::Collect
+ name: METHODS
+ version: 4.004
+ -
+ class: Pod::Weaver::Section::Collect
+ name: FUNCTIONS
+ version: 4.004
+ -
+ class: Pod::Weaver::Section::Leftovers
+ name: '@Default/Leftovers'
+ version: 4.004
+ -
+ class: Pod::Weaver::Section::Region
+ name: '@Default/postlude'
+ version: 4.004
+ -
+ class: Pod::Weaver::Section::Bugs
+ name: '@Default/Bugs'
+ version: 4.004
+ -
+ class: Pod::Weaver::Section::Authors
+ name: '@Default/Authors'
+ version: 4.004
+ -
+ class: Pod::Weaver::Section::Legal
+ name: '@Default/Legal'
+ version: 4.004
name: '@GRS/PodWeaver'
- version: 3.102000
+ version: 4.002
-
class: Dist::Zilla::Plugin::PerlTidy
name: '@GRS/PerlTidy'
@@ -1,7 +1,7 @@
This archive contains the distribution MooX-Options,
-version 4.003:
+version 4.008:
Explicit Options eXtension for Object Class
@@ -4,7 +4,16 @@ MooX::Options - Explicit Options eXtension for Object Class
# VERSION
-version 4.003
+version 4.008
+
+# DESCRIPTION
+
+Create a command line tool with your [Mo](https://metacpan.org/pod/Mo), [Moo](https://metacpan.org/pod/Moo), [Moose](https://metacpan.org/pod/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](https://metacpan.org/pod/Getopt::Long::Descriptive)
+to generate a command line tool.
# SYNOPSIS
@@ -14,7 +23,6 @@ In myOptions.pm :
use Moo;
use MooX::Options;
-
option 'show_this_file' => (
is => 'ro',
format => 's',
@@ -29,10 +37,8 @@ In myTool.pl :
use myOptions;
use Path::Class;
-
my $opt = myOptions->new_with_options;
-
say "Content of the file : ",
file($opt->show_this_file)->slurp;
@@ -46,15 +52,12 @@ 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
@@ -67,22 +70,13 @@ The manual :
perl myTool.pl --man
-# DESCRIPTION
-
-Create a command line tool with your [Mo](http://search.cpan.org/perldoc?Mo), [Moo](http://search.cpan.org/perldoc?Moo), [Moose](http://search.cpan.org/perldoc?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 use [Getopt::Long::Descriptive](http://search.cpan.org/perldoc?Getopt::Long::Descriptive)
-to generate a command line tool.
-
# 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.
+It will parse your command line params and your inline params, validate and call the `new` method.
myTool --str=ko
@@ -91,83 +85,83 @@ It will parse your command line params and your inline params, validate and call
## option
-The option keyword replace the 'has' method, and add support specials options for the command line only.
+The `option` keyword replaces the `has` method and adds support for special options for the command line only.
-See ["OPTION PARAMETERS"](#OPTION PARAMETERS) for the documentation.
+See ["OPTION PARAMETERS"](#option-parameters) for the documentation.
## options\_usage | --help
-It display the usage message and return the exit code
+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 fire if the command option "--help" is passed.
+This method is also automatically fired if the command option "--help" is passed.
myTool --help
## options\_man | --man
-It display the manual.
+It displays the manual.
my $t = t->new_with_options();
$t->options_man();
-This is automatically fire if the command option "--man" is passed.
+This is automatically fired if the command option "--man" is passed.
myTool --man
## options\_short\_usage | --usage
-It display a short version of the help message.
+It displays a short version of the help message.
my $t = t->new_with_options();
$t->options_short_usage($exit_code);
-This is automatically fire if the command option "--usage" is passed.
+This is automatically fired if the command option "--usage" is passed.
myTool --usage
# IMPORT PARAMETERS
-The list of parameters support by [MooX::Options](http://search.cpan.org/perldoc?MooX::Options).
+The list of parameters supported by [MooX::Options](https://metacpan.org/pod/MooX::Options).
## flavour
-Pass extra arguments for [Getopt::Long::Descriptive](http://search.cpan.org/perldoc?Getopt::Long::Descriptive). It is usefull if you
-want to configure Getopt::Long.
+Passes extra arguments for [Getopt::Long::Descriptive](https://metacpan.org/pod/Getopt::Long::Descriptive). It is useful if you
+want to configure [Getopt::Long](https://metacpan.org/pod/Getopt::Long).
use MooX::Options flavour => [qw( pass_through )];
-Any flavour is pass to [Getopt::Long](http://search.cpan.org/perldoc?Getopt::Long) as a configuration, check the doc to see what is possible.
+Any flavour is passed to [Getopt::Long](https://metacpan.org/pod/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.
+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 your want to disactivate some of them, you can use this parameter.
-In that case, the 'option' keyword will just works like an 'has'.
+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 to __new\_with\_options__ have a higher priority than the commandline options.
+By default, arguments passed to `new_with_options` have a higher priority than the command line options.
-This parameter give to the commandline an higher priority.
+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::ConfigFromFile](http://search.cpan.org/perldoc?MooX::ConfigFromFile) in your module.
-The config option will be used between the commandline and the parameters.
+This parameter will load [MooX::ConfigFromFile](https://metacpan.org/pod/MooX::ConfigFromFile) in your module.
+The config option will be used between the command line and parameters.
myTool :
@@ -179,7 +173,7 @@ In /etc/myTool.json
# OPTION PARAMETERS
-The keyword __option__ extend the keyword __has__ with specific parameters for the commandline.
+The keyword `option` extend the keyword `has` with specific parameters for the command line.
## doc | documentation
@@ -187,19 +181,18 @@ Documentation for the command line option.
## long\_doc
-Documentation for the man page. By default the __doc__ parameter will be used.
+Documentation for the man page. By default the `doc` parameter will be used.
-See also [Man parameters](http://search.cpan.org/perldoc?MooX::Options::Manual::Man) to get more examples to build a nice man page.
+See also [Man parameters](https://metacpan.org/pod/MooX::Options::Manual::Man) to get more examples how to build a nice man page.
## required
-This attribute indicate that the parameter is mandatory.
-This attribute is not really used by [MooX::Options](http://search.cpan.org/perldoc?MooX::Options) but the error message will be handle by it to
-display a consistant error message.
+This attribute indicates that the parameter is mandatory.
+This attribute is not really used by [MooX::Options](https://metacpan.org/pod/MooX::Options) but ensures that consistent error message will be displayed.
## format
-Format of the params. It is the same as [Getopt::Long::Descriptive](http://search.cpan.org/perldoc?Getopt::Long::Descriptive).
+Format of the params, same as [Getopt::Long::Descriptive](https://metacpan.org/pod/Getopt::Long::Descriptive).
- i : integer
- i@: array of integer
@@ -209,14 +202,14 @@ Format of the params. It is the same as [Getopt::Long::Descriptive](http://searc
By default, it's a boolean value.
-Take a look of available formats with [Getopt::Long::Descriptive](http://search.cpan.org/perldoc?Getopt::Long::Descriptive).
+Take a look of available formats with [Getopt::Long::Descriptive](https://metacpan.org/pod/Getopt::Long::Descriptive).
You need to understand that everything is explicit here.
-If you use [Moose](http://search.cpan.org/perldoc?Moose) and you attribute has __isa =__ 'Array\[Int\]'>, that will not implied the format 'i@'.
+If you use [Moose](https://metacpan.org/pod/Moose) and your attribute has `isa => 'Array[Int]'`, that will __not__ imply the format `i@`.
## format json : special format support
-The parameter will be treat like a json string.
+The parameter will be treated like a json string.
option 'hash' => (is => 'ro', json => 1);
@@ -224,7 +217,7 @@ The parameter will be treat like a json string.
## negativable
-It add the negative version for the option.
+It adds the negative version for the option.
option 'verbose' => (is => 'ro', negativable => 1);
@@ -233,9 +226,9 @@ It add the negative version for the option.
## repeatable
-It append to the ["format"](#format) the array attribute __@__.
+It appends to the ["format"](#format) the array attribute `@`.
-I advice to add a default value to your attribute to always have an array.
+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 { [] });
@@ -248,11 +241,10 @@ For repeatable option, you can add the autosplit feature with your specific para
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
+It will also handle quoted params with the autosplit.
option testStr => (is => 'ro', format => 's@', default => sub {[]}, autosplit => ',');
@@ -282,16 +274,16 @@ You can also use a shorter option without attribute :
## order
-Specified the order of the attribute. If you want to push some attribute at the end of the list.
-By default all option has an order set to __0__, and the option is sorted by their name.
+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);
# ADDITIONAL MANUALS
-- [Man parameters](http://search.cpan.org/perldoc?MooX::Options::Manual::Man)
-- [Using namespace::clean](http://search.cpan.org/perldoc?MooX::Options::Manual::NamespaceClean)
-- [Manage your tools with MooX::Cmd](http://search.cpan.org/perldoc?MooX::Options::Manual::MooXCmd)
+- [Man parameters](https://metacpan.org/pod/MooX::Options::Manual::Man)
+- [Using namespace::clean](https://metacpan.org/pod/MooX::Options::Manual::NamespaceClean)
+- [Manage your tools with MooX::Cmd](https://metacpan.org/pod/MooX::Options::Manual::MooXCmd)
# EXTERNAL EXAMPLES
@@ -301,8 +293,8 @@ By default all option has an order set to __0__, and the option is sorted by the
- Matt S. Trout (mst) <mst@shadowcat.co.uk> : For his patience and advice.
- Tomas Doran (t0m) <bobtfish@bobtfish.net> : To help me release the new version, and using it :)
-- Torsten Raudssus (Getty) : to use it a lot in [DuckDuckGo](http://duckduckgo.com) (go to see [MooX](http://search.cpan.org/perldoc?MooX) module also)
-- Jens Rehsack (REHSACK) : Use with [PkgSrc](http://www.pkgsrc.org/), and many really good idea ([MooX::Cmd](http://search.cpan.org/perldoc?MooX::Cmd), [MooX::ConfigFromFile](http://search.cpan.org/perldoc?MooX::ConfigFromFile), and more to come I'm sure)
+- Torsten Raudssus (Getty) : to use it a lot in [DuckDuckGo](http://duckduckgo.com) (go to see [MooX](https://metacpan.org/pod/MooX) module also)
+- Jens Rehsack (REHSACK) : Use with [PkgSrc](http://www.pkgsrc.org/), and many really good idea ([MooX::Cmd](https://metacpan.org/pod/MooX::Cmd), [MooX::ConfigFromFile](https://metacpan.org/pod/MooX::ConfigFromFile), and more to come I'm sure)
# BUGS
@@ -2,7 +2,7 @@ name = MooX-Options
license = Perl_5
copyright_holder = celogeek <me@celogeek.com>
copyright_year = 2013
-version = 4.003
+version = 4.008
[@GRS]
-remove = AutoPrereqs
@@ -12,7 +12,7 @@ package MooX::Options::Descriptive::Usage;
use strict;
use warnings;
-our $VERSION = '4.003'; # VERSION
+our $VERSION = '4.008'; # VERSION
use feature 'say';
use Text::WrapI18N;
use Term::Size::Any qw/chars/;
@@ -239,7 +239,7 @@ MooX::Options::Descriptive::Usage - Usage class
=head1 VERSION
-version 4.003
+version 4.008
=head1 DESCRIPTION
@@ -12,7 +12,7 @@ package MooX::Options::Descriptive;
use strict;
use warnings;
-our $VERSION = '4.003'; # VERSION
+our $VERSION = '4.008'; # VERSION
use Getopt::Long 2.38;
use Getopt::Long::Descriptive 0.091;
@@ -33,7 +33,7 @@ MooX::Options::Descriptive - This method extend Getopt::Long::Descriptive to cha
=head1 VERSION
-version 4.003
+version 4.008
=head1 DESCRIPTION
@@ -11,16 +11,16 @@ MooX::Options::Manual::Man - More documentation for the man option
=head1 VERSION
-version 4.003
-
-=head1 SYNOPSIS
-
- myTool --man
+version 4.008
=head1 DESCRIPTION
You can add more documentation for the man option. This is the long option.
+=head1 SYNOPSIS
+
+ myTool --man
+
=head1 PARAMETERS
=head2 description
@@ -11,7 +11,7 @@ MooX::Options::Manual::MooXCmd - Manage your tools with MooX::Cmd
=head1 VERSION
-version 4.003
+version 4.008
=head1 DESCRIPTION
@@ -11,7 +11,7 @@ MooX::Options::Manual::NamespaceClean - Use namespace::clean with MooX::Options
=head1 VERSION
-version 4.003
+version 4.008
=head1 DESCRIPTION
@@ -12,7 +12,7 @@ package MooX::Options::Role;
use strict;
use warnings;
-our $VERSION = '4.003'; # VERSION
+our $VERSION = '4.008'; # VERSION
use MRO::Compat;
use MooX::Options::Descriptive;
@@ -28,15 +28,7 @@ use Scalar::Util qw/blessed/;
sub _option_name {
my ( $name, %data ) = @_;
- my $cmdline_name = $name;
- $cmdline_name .= '|' . $data{short} if defined $data{short};
-
- #dash name support
- my $dash_name = $name;
- $dash_name =~ tr/_/-/;
- if ( $dash_name ne $name ) {
- $cmdline_name .= '|' . $dash_name;
- }
+ my $cmdline_name = join( '|', grep {defined} ( $name, $data{short} ) );
$cmdline_name .= '+' if $data{repeatable} && !defined $data{format};
$cmdline_name .= '!' if $data{negativable};
$cmdline_name .= '=' . $data{format} if defined $data{format};
@@ -64,14 +56,14 @@ sub _options_prepare_descriptive {
push @options, [ _option_name( $name, %data ), $doc ];
if ( defined $data{autosplit} ) {
- $has_to_split{"--${name}"} = Data::Record->new(
+ $has_to_split{$name} = Data::Record->new(
{ split => $data{autosplit}, unless => $RE{quoted} } );
if ( my $short = $data{short} ) {
- $has_to_split{"-${short}"} = $has_to_split{"--${name}"};
+ $has_to_split{$short} = $has_to_split{ ${name} };
}
- for ( my $i = 1; $i < length($name); $i++ ) {
+ for ( my $i = 1; $i <= length($name); $i++ ) {
my $long_short = substr( $name, 0, $i );
- $has_to_split{"--${long_short}"} = $has_to_split{"--${name}"};
+ $has_to_split{$long_short} = $has_to_split{ ${name} };
}
}
}
@@ -79,19 +71,54 @@ sub _options_prepare_descriptive {
return \@options, \%has_to_split;
}
-sub _options_split_with {
- my ($has_to_split) = @_;
+sub _options_fix_argv {
+ my ( $option_data, $has_to_split ) = @_;
my @new_argv;
#parse all argv
- for my $i ( 0 .. $#ARGV ) {
- my $arg = $ARGV[$i];
- my ( $arg_name, $arg_values ) = split( /=/x, $arg, 2 );
- unless ( defined $arg_values ) {
- $arg_values = $ARGV[ ++$i ];
+ while ( my $arg = shift @ARGV ) {
+ if ( $arg eq '--' ) {
+ push @new_argv, $arg, @ARGV;
+ last;
+ }
+ if ( index( $arg, '-' ) != 0 ) {
+ push @new_argv, $arg;
+ next;
+ }
+
+ my ( $arg_name_with_dash, $arg_values ) = split( /=/x, $arg, 2 );
+ if ( index( $arg_name_with_dash, '--' ) < 0 && !defined $arg_values )
+ {
+ $arg_values
+ = length($arg_name_with_dash) > 2
+ ? substr( $arg_name_with_dash, 2 )
+ : undef;
+ $arg_name_with_dash = substr( $arg_name_with_dash, 0, 2 );
}
- if ( my $rec = $has_to_split->{$arg_name} ) {
+ unshift @ARGV, $arg_values if defined $arg_values;
+
+ my ( $dash, $negative, $arg_name_without_dash )
+ = $arg_name_with_dash =~ /^(\-+)(no\-)?(.*)$/x;
+ $arg_name_without_dash =~ s/\-/_/gx;
+
+ my $arg_name = $dash;
+
+ if ( defined $negative ) {
+ if ( exists $option_data->{$arg_name_without_dash}
+ && $option_data->{$arg_name_without_dash}{negativable} )
+ {
+ $arg_name .= 'no-';
+ }
+ else {
+ $arg_name .= 'no_';
+ }
+ }
+
+ $arg_name .= $arg_name_without_dash;
+
+ if ( my $rec = $has_to_split->{$arg_name_without_dash} ) {
+ $arg_values = shift @ARGV;
foreach my $record ( $rec->records($arg_values) ) {
#remove the quoted if exist to chain
@@ -100,7 +127,7 @@ sub _options_split_with {
}
}
else {
- push @new_argv, $arg;
+ push @new_argv, $arg_name;
}
}
@@ -190,7 +217,7 @@ sub parse_options {
= _options_prepare_descriptive( \%options_data );
local @ARGV = @ARGV if $options_config{protect_argv};
- @ARGV = _options_split_with($has_to_split) if %$has_to_split;
+ @ARGV = _options_fix_argv( \%options_data, $has_to_split );
my @flavour;
if ( defined $options_config{flavour} ) {
@@ -351,7 +378,7 @@ MooX::Options::Role - role that is apply to your object
=head1 VERSION
-version 4.003
+version 4.008
=head1 METHODS
@@ -379,7 +406,7 @@ Display quick usage message, with only the list of options
=head2 options_man
-Display a pod like a manuel
+Display a pod like a manual
=head1 USAGE
@@ -12,7 +12,7 @@ package MooX::Options;
use strict;
use warnings;
-our $VERSION = '4.003'; # VERSION
+our $VERSION = '4.008'; # VERSION
use Carp;
my @OPTIONS_ATTRIBUTES
@@ -197,7 +197,16 @@ MooX::Options - Explicit Options eXtension for Object Class
=head1 VERSION
-version 4.003
+version 4.008
+
+=head1 DESCRIPTION
+
+Create a command line tool with your L<Mo>, L<Moo>, L<Moose> objects.
+
+Everything is explicit. You have an C<option> keyword to replace the usual C<has> to explicitly use your attribute into the command line.
+
+The C<option> keyword takes additional parameters and uses L<Getopt::Long::Descriptive>
+to generate a command line tool.
=head1 SYNOPSIS
@@ -254,22 +263,13 @@ The manual :
perl myTool.pl --man
-=head1 DESCRIPTION
-
-Create a command line tool with your L<Mo>, L<Moo>, L<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 use L<Getopt::Long::Descriptive>
-to generate a command line tool.
-
=head1 IMPORTED METHODS
The list of the methods automatically imported into your class.
=head2 new_with_options
-It will parse your command line params and your inline params, validate and call the 'new' method.
+It will parse your command line params and your inline params, validate and call the C<new> method.
myTool --str=ko
@@ -278,83 +278,83 @@ It will parse your command line params and your inline params, validate and call
=head2 option
-The option keyword replace the 'has' method, and add support specials options for the command line only.
+The C<option> keyword replaces the C<has> method and adds support for special options for the command line only.
See L</OPTION PARAMETERS> for the documentation.
=head2 options_usage | --help
-It display the usage message and return the exit code
+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 fire if the command option "--help" is passed.
+This method is also automatically fired if the command option "--help" is passed.
myTool --help
=head2 options_man | --man
-It display the manual.
+It displays the manual.
my $t = t->new_with_options();
$t->options_man();
-This is automatically fire if the command option "--man" is passed.
+This is automatically fired if the command option "--man" is passed.
myTool --man
=head2 options_short_usage | --usage
-It display a short version of the help message.
+It displays a short version of the help message.
my $t = t->new_with_options();
$t->options_short_usage($exit_code);
-This is automatically fire if the command option "--usage" is passed.
+This is automatically fired if the command option "--usage" is passed.
myTool --usage
=head1 IMPORT PARAMETERS
-The list of parameters support by L<MooX::Options>.
+The list of parameters supported by L<MooX::Options>.
=head2 flavour
-Pass extra arguments for L<Getopt::Long::Descriptive>. It is usefull if you
-want to configure Getopt::Long.
+Passes extra arguments for L<Getopt::Long::Descriptive>. It is useful if you
+want to configure L<Getopt::Long>.
use MooX::Options flavour => [qw( pass_through )];
-Any flavour is pass to L<Getopt::Long> as a configuration, check the doc to see what is possible.
+Any flavour is passed to L<Getopt::Long> as a configuration, check the doc to see what is possible.
=head2 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.
+By default, C<@ARGV> is protected. If you want to do something else on it, use this option and it will change the real C<@ARGV>.
use MooX::Options protect_argv => 0;
=head2 skip_options
-If you have Role with options and your want to disactivate some of them, you can use this parameter.
-In that case, the 'option' keyword will just works like an 'has'.
+If you have Role with options and you want to deactivate some of them, you can use this parameter.
+In that case, the C<option> keyword will just work like an C<has>.
use MooX::Options skip_options => [qw/multi/];
=head2 prefer_commandline
-By default, arguments to B<new_with_options> have a higher priority than the commandline options.
+By default, arguments passed to C<new_with_options> have a higher priority than the command line options.
-This parameter give to the commandline an higher priority.
+This parameter will give the command line an higher priority.
use MooX::Options prefer_commandline => 1;
=head2 with_config_from_file
This parameter will load L<MooX::ConfigFromFile> in your module.
-The config option will be used between the commandline and the parameters.
+The config option will be used between the command line and parameters.
myTool :
@@ -366,7 +366,7 @@ In /etc/myTool.json
=head1 OPTION PARAMETERS
-The keyword B<option> extend the keyword B<has> with specific parameters for the commandline.
+The keyword C<option> extend the keyword C<has> with specific parameters for the command line.
=head2 doc | documentation
@@ -374,19 +374,18 @@ Documentation for the command line option.
=head2 long_doc
-Documentation for the man page. By default the B<doc> parameter will be used.
+Documentation for the man page. By default the C<doc> parameter will be used.
-See also L<Man parameters|MooX::Options::Manual::Man> to get more examples to build a nice man page.
+See also L<Man parameters|MooX::Options::Manual::Man> to get more examples how to build a nice man page.
=head2 required
-This attribute indicate that the parameter is mandatory.
-This attribute is not really used by L<MooX::Options> but the error message will be handle by it to
-display a consistant error message.
+This attribute indicates that the parameter is mandatory.
+This attribute is not really used by L<MooX::Options> but ensures that consistent error message will be displayed.
=head2 format
-Format of the params. It is the same as L<Getopt::Long::Descriptive>.
+Format of the params, same as L<Getopt::Long::Descriptive>.
=over
@@ -407,11 +406,11 @@ By default, it's a boolean value.
Take a look of available formats with L<Getopt::Long::Descriptive>.
You need to understand that everything is explicit here.
-If you use L<Moose> and you attribute has B<isa => 'Array[Int]'>, that will not implied the format 'i@'.
+If you use L<Moose> and your attribute has C<< isa => 'Array[Int]' >>, that will B<not> imply the format C<i@>.
=head2 format json : special format support
-The parameter will be treat like a json string.
+The parameter will be treated like a json string.
option 'hash' => (is => 'ro', json => 1);
@@ -419,7 +418,7 @@ The parameter will be treat like a json string.
=head2 negativable
-It add the negative version for the option.
+It adds the negative version for the option.
option 'verbose' => (is => 'ro', negativable => 1);
@@ -428,9 +427,9 @@ It add the negative version for the option.
=head2 repeatable
-It append to the L</format> the array attribute B<@>.
+It appends to the L</format> the array attribute C<@>.
-I advice to add a default value to your attribute to always have an array.
+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 { [] });
@@ -446,7 +445,7 @@ For repeatable option, you can add the autosplit feature with your specific para
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
+It will also handle quoted params with the autosplit.
option testStr => (is => 'ro', format => 's@', default => sub {[]}, autosplit => ',');
@@ -476,8 +475,8 @@ You can also use a shorter option without attribute :
=head2 order
-Specified the order of the attribute. If you want to push some attribute at the end of the list.
-By default all option has an order set to B<0>, and the option is sorted by their name.
+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 C<0>, and options are sorted by their names.
option 'at_the_end' => (is => 'ro', order => 999);
@@ -1,7 +1,8 @@
+use 5.006;
use strict;
use warnings;
-# this test was generated with Dist::Zilla::Plugin::Test::Compile 2.037
+# this test was generated with Dist::Zilla::Plugin::Test::Compile 2.039
use Test::More tests => 4 + ( $ENV{AUTHOR_TESTING} ? 1 : 0 );
@@ -18,11 +19,12 @@ use File::Spec;
use IPC::Open3;
use IO::Handle;
+open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!";
+
my @warnings;
for my $lib (@module_files) {
# see L<perlfaq8/How can I capture STDERR from an external command?>
- open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!";
my $stderr = IO::Handle->new;
my $pid = open3( $stdin, '>&STDERR', $stderr, $^X, $inc_switch, '-e',
@@ -149,10 +149,40 @@ subtest "split_complexe_str" => sub {
is_deeply( $t->split_str, [qw/a b c/], 'str req is ok' );
}
{
+ local @ARGV = ("--split-str=a,b,c");
+ my $t = sp_str->new_with_options();
+ is_deeply( $t->split_str, [qw/a b c/], 'str req is ok' );
+ }
+ {
+ local @ARGV = ("--split_conflict_str1=a,b,c");
+ my $t = sp_str->new_with_options();
+ is_deeply( $t->split_conflict_str1, [qw/a b c/], 'str req is ok' );
+ }
+ {
+ local @ARGV = ("--split_conflict-str1=a,b,c");
+ my $t = sp_str->new_with_options();
+ is_deeply( $t->split_conflict_str1, [qw/a b c/], 'str req is ok' );
+ }
+ {
+ local @ARGV = ("--split-conflict_str1=a,b,c");
+ my $t = sp_str->new_with_options();
+ is_deeply( $t->split_conflict_str1, [qw/a b c/], 'str req is ok' );
+ }
+ {
+ local @ARGV = ("--split-conflict-str1=a,b,c");
+ my $t = sp_str->new_with_options();
+ is_deeply( $t->split_conflict_str1, [qw/a b c/], 'str req is ok' );
+ }
+ {
local @ARGV = ('--split_str=a,"b,c",d');
my $t = sp_str->new_with_options();
is_deeply( $t->split_str, [ 'a', 'b,c', 'd' ], 'str req is ok' );
}
+ {
+ local @ARGV = ('--split-str=a,"b,c",d');
+ my $t = sp_str->new_with_options();
+ is_deeply( $t->split_str, [ 'a', 'b,c', 'd' ], 'str req is ok' );
+ }
done_testing();
};
@@ -173,6 +203,11 @@ subtest "split_complexe_str_short" => sub {
my $t = sp_str_short->new_with_options();
is_deeply( $t->split_str, [ 'a', 'b,c', 'd' ], 'str req is ok' );
}
+ {
+ local @ARGV = ('-z','a,"b,c",d');
+ my $t = sp_str_short->new_with_options();
+ is_deeply( $t->split_str, [ 'a', 'b,c', 'd' ], 'str req is ok' );
+ }
done_testing();
};
@@ -183,6 +218,11 @@ subtest "split_str_shorter_name" => sub {
my $t = sp_str->new_with_options();
is_deeply( $t->split_str, [qw/a b c/], 'str req is ok' );
}
+ {
+ local @ARGV = ("--split-st=a,b,c");
+ my $t = sp_str->new_with_options();
+ is_deeply( $t->split_str, [qw/a b c/], 'str req is ok' );
+ }
note "shorter long split with conflict";
{
local @ARGV = ("--split_co=a,b,c");
@@ -190,6 +230,11 @@ subtest "split_str_shorter_name" => sub {
sp_str->new_with_options();
};
ok $trap->stderr =~ qr/Option\ssplit_co\sis\sambiguous/, 'conflict detected';
+ local @ARGV = ("--split-co=a,b,c");
+ trap {
+ sp_str->new_with_options();
+ };
+ ok $trap->stderr =~ qr/Option\ssplit_co\sis\sambiguous/, 'conflict detected';
}
done_testing();
};