Skip Menu |

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

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

People
Owner: bobtfish [...] bobtfish.net
Requestors: MAROS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.23
Fixed in: (no value)



Subject: Warning and fails to parse all command line options
See attached testcase. Use of uninitialized value in list assignment at /Volumes/Data/PerlModules/moosex-getopt/lib/MooseX/Getopt.pm line 107. v5.10.1 built for darwin-thread-multi-2level Cheers Maroš
Subject: 103_fail.t
#!/usr/bin/perl use strict; use warnings; use Test::More tests => 4; { package App; use Moose; use Moose::Util::TypeConstraints; has 'TrackingNumber' => ( is => 'rw', isa => 'TrackingNumber', documentation => 'Shipment tracking number', ); subtype 'TrackingNumber' => as 'Str' => where { my $trackingnumber = $_; return 0 unless ($trackingnumber =~ m/^1Z(?<tracking>[A-Z0-9]{8}\d{7})(?<checksum>\d)$/); return 1; } => message { "Tracking numbers must start withn '1Z' and contain 15 additional characters" }; } { package App::Commandline; use Moose; extends qw(App); with qw(MooseX::Getopt); MooseX::Getopt::OptionTypeMap->add_option_type_to_map( 'TrackingNumber' => '=s', ); has 'otherparam' => ( is => 'rw', isa => 'Str', ); } { local @ARGV = ('--TrackingNumber','1Z1234567812345670','--otherparam','foo'); my $app = App::Commandline->new_with_options; isa_ok($app, 'App'); isa_ok($app, 'App::Commandline'); is($app->TrackingNumber, '1Z1234567812345670', '... TrackingNumber is as expected'); is($app->otherparam, 'foo', '... otherparam is as expected'); }
Subject: Patch
Patch+Test for the mentioned problem is attached. Cheers Maros
From e7e9406497f6a1a6bcaa681ee031e195045f24f2 Mon Sep 17 00:00:00 2001 From: Maros Kollar <maros@k-1.com> Date: Fri, 23 Oct 2009 18:13:24 +0200 Subject: [PATCH] Fix bug when handling upper/mixedcase accessors --- lib/MooseX/Getopt.pm | 4 ++-- t/103_uc_bug.t | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 t/103_uc_bug.t diff --git a/lib/MooseX/Getopt.pm b/lib/MooseX/Getopt.pm index 90a9d77..250a2fb 100644 --- a/lib/MooseX/Getopt.pm +++ b/lib/MooseX/Getopt.pm @@ -128,7 +128,7 @@ sub _traditional_spec { foreach my $opt ( @{ $params{options} } ) { push @options, $opt->{opt_string}; - my $identifier = $opt->{name}; + my $identifier = lc($opt->{name}); $identifier =~ s/\W/_/g; # Getopt::Long does this to all option names $name_to_init_arg{$identifier} = $opt->{init_arg}; @@ -160,7 +160,7 @@ sub _gld_spec { }, ]; - my $identifier = $opt->{name}; + my $identifier = lc($opt->{name}); $identifier =~ s/\W/_/g; # Getopt::Long does this to all option names $name_to_init_arg{$identifier} = $opt->{init_arg}; diff --git a/t/103_uc_bug.t b/t/103_uc_bug.t new file mode 100644 index 0000000..f81ba01 --- /dev/null +++ b/t/103_uc_bug.t @@ -0,0 +1,32 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use 5.010; + +use Test::More tests => 3; + +{ + package App; + use Moose; + with qw(MooseX::Getopt); + + has 'TrackingNumber' => ( + is => 'rw', + isa => 'Str', + ); + + has 'otherparam' => ( + is => 'rw', + isa => 'Str', + ); +} + +{ + local @ARGV = ('--TrackingNumber','1Z1234567812345670','--otherparam','foo'); + + my $app = App->new_with_options; + isa_ok($app, 'App'); + is($app->TrackingNumber, '1Z1234567812345670', '... TrackingNumber is as expected'); + is($app->otherparam, 'foo', '... otherparam is as expected'); +} -- 1.6.5
Thanks. Applied and released as 0.24