Subject: | Very strange handling of -v/--version |
$ cat moose.pl
package Foo;
use Moose;
use MooseX::Types::Moose qw<Bool Str>;
use MooseX::Types::Path::Class qw<File>;
our $VERSION = '0.01';
has configfile => (
traits => [qw(NoGetopt)],
isa => File,
coerce => 1,
is => 'ro',
);
has from_config => (
traits => [qw(NoGetopt)],
isa => Str,
is => 'ro',
);
#has print_version => (
# traits => [qw(Getopt)],
# isa => Bool,
# is => 'ro',
# cmd_flag => 'version',
# cmd_aliases => 'v',
# documentation => 'Print version and exit',
#);
with 'MooseX::Getopt';
#with 'MooseX::SimpleConfig';
sub run {
my ($self) = @_;
if ($self->print_version) {
print "foo $VERSION\n";
exit;
}
}
package Test;
Foo->new_with_options(configfile => 'foo.yml')->run();
##########################
$ cat foo.yml
from_config: "foo"
$ perl moose.pl --version
moose.pl
(Getopt::Long::GetOptions version 2.37; Perl version 5.10.0)
$ perl moose.pl -v
Unknown option: v
usage: moose.pl
$ perl moose.pl -V
Unknown option: V
usage: moose.pl
# now I uncomment the "#has print_version" statement in moose.pl
$ perl moose.pl --version
foo 0.01
$ perl moose.pl -v
foo 0.01
$ perl moose.pl -V
Unknown option: V
usage: moose.pl [-v] [long options...]
-v --version Print version and exit
# now I uncomment "#with 'MooseX::SimpleConfig';" in moose.pl
$ perl moose.pl --version
moose.pl
(Getopt::Long::GetOptions version 2.37; Perl version 5.10.0)
$ perl moose.pl -v
moose.pl
(Getopt::Long::GetOptions version 2.37; Perl version 5.10.0)
$ perl moose.pl -V
moose.pl
(Getopt::Long::GetOptions version 2.37; Perl version 5.10.0)
########################
In the first case, why does --version return Getopt::Long's
autogenerated version reply? MooseX::Getopt never turns on
Getopt::Long's "auto_version" nor does it explicitly use/require
Getopt::Long >2.32 which would automatically turn on "auto_version".
The second case works as expected. My provided version options are used
in both cases, and it's case sensitive (v != V).
In the third case, after adding MooseX::SimpleConfig to the mix, I get
Getopt::Long's autogenerated reply for both -v and --version, instead of
the ones I specified. Why? And why does it ignore case and accept -V too?