Skip Menu |

This queue is for tickets about the MooseX-Getopt CPAN distribution.

Report information
The Basics
Id: 53981
Status: resolved
Priority: 0/
Queue: MooseX-Getopt

People
Owner: Nobody in particular
Requestors: hinrik.sig [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: (no value)
Fixed in: (no value)



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?
Attached some tests.
Subject: version_options.tar.gz
Download version_options.tar.gz
application/x-gzip 772b

Message body not shown because it is not plain text.

Assigning to current maintainer. bobtfish, can you please take a look?
On Sat Oct 29 08:14:46 2011, GAAL wrote: Show quoted text
> Assigning to current maintainer. bobtfish, can you please take a look?
t0m (BOBTFISH) poked me to investigate this... Firstly, I can tell you that things behave the way they do *now* because of "use Getopt::Long 2.37 ();" in MooseX::Getopt::Basic, which has been there since Sat Jun 5 12:03:52 2010. Now this is after the original bug report. As to why things were behaving that back then (2010), too... Adding this to the bottom of your script (in the version with print_version commented out), *and* changing MooseX::Getopt::Basic so it again no longer requires a specific version of Getopt::Long: $Getopt::Long::debug = 1; ; perl -Ilib RT53981/moose_orig.pl --version Getopt::Long 2.38 ($Revision: 2.76 $) called from package "Getopt::Long::Descriptive". argv: (--version) autoabbrev=1,bundling=1,getopt_compat=1,gnu_compat=0,order=1, ignorecase=1,requested_version=2.33,passthrough=0,genprefix="(--|-|\+)",longprefix="(--)". => user linkage: HASH(0x100d2d258) => $opctl{no-?} = ARRAY(0x100d2dd18) ["!","help","<undef>",$,,] $opctl{usage} = ARRAY(0x100d2dfb8) ["","help","<undef>",$,,] $opctl{nohelp} = ARRAY(0x100d2dd18) ["!","help","<undef>",$,,] $opctl{nousage} = ARRAY(0x100d2dd18) ["!","help","<undef>",$,,] $opctl{version} = ARRAY(0x100d2dd00) ["","version","0",&,<undef>,] $opctl{no-help} = ARRAY(0x100d2dd18) ["!","help","<undef>",$,,] $opctl{no?} = ARRAY(0x100d2dd18) ["!","help","<undef>",$,,] $opctl{?} = ARRAY(0x100d2e0a8) ["","help","<undef>",$,,] $opctl{help} = ARRAY(0x100d2dec8) ["","help","<undef>",$,,] $opctl{no-usage} = ARRAY(0x100d2dd18) ["!","help","<undef>",$,,] => arg "--version" => find "--version" => split "--"+"version" => 1 hits (version) with "version" out of 10 => found ["","version","0",&,<undef>,] for "version" => cname for "version" is "version" => ref($L{version}) -> CODE => &L{version}("version", "1") RT53981/moose_orig.pl (Getopt::Long::GetOptions version 2.38; Perl version 5.14.2) Conclusion: something is still requesting a specific version, that is resulting in auto_version being turned on. Next step: look at the stack trace in Getopt::Long::import, to see who is doing the initial library load. It's Getopt::Long::Descriptive, line 11, which does indeed do "use Getopt::Long 2.33;". Looking at the source for Getopt::Long::Descriptive, I see the explicit version has been in place since Thu Dec 3 11:09:28 2009 -0500 - so this likely explains the behaviour you're seeing (you didn't report the version of Getopt::Long::Descriptive you were using, but it's probably safe to assume it was current). HTH; sorry it comes so late. PS. If you don't like the auto_version behaviour, you can explicitly turn it off in your app, with: use Getopt::Long qw(:config no_auto_version);