From: Shlomi Fish Date: Wed, 12 Aug 2009 22:03:14 +0000 (+0300) Subject: Enable the argv argument to the constructor. X-Git-Tag: 0.22~13 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-Getopt.git;a=commitdiff_plain;h=f7655c45b040d61c8e6aa2e588542977c0368f36 Enable the argv argument to the constructor. Previously, it wasn't passed. --- diff --git a/ChangeLog b/ChangeLog index 10b28cf..d4651d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ Revision history for Perl extension MooseX-Getopt + * MooseX::Getopt + - Enable and document the argv parameter to the constructor. + 0.20 Wed. July 9 2009 ~ fix MANIFEST.SKIP to avoid double-packaging diff --git a/lib/MooseX/Getopt.pm b/lib/MooseX/Getopt.pm index 67725e9..fea359f 100644 --- a/lib/MooseX/Getopt.pm +++ b/lib/MooseX/Getopt.pm @@ -69,7 +69,7 @@ sub new_with_options { sub _parse_argv { my ( $class, %params ) = @_; - local @ARGV = @{ $params{argv} || \@ARGV }; + local @ARGV = @{ $params{params}{argv} || \@ARGV }; my ( $opt_spec, $name_to_init_arg ) = ( HAVE_GLD ? $class->_gld_spec(%params) : $class->_traditional_spec(%params) ); diff --git a/t/101_argv_bug.t b/t/101_argv_bug.t new file mode 100644 index 0000000..1a84cec --- /dev/null +++ b/t/101_argv_bug.t @@ -0,0 +1,99 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 7; + +BEGIN { + # TEST + use_ok('MooseX::Getopt'); +} + +{ + package App; + use Moose; + + with 'MooseX::Getopt'; + + has 'data' => ( + metaclass => 'MooseX::Getopt::Meta::Attribute', + is => 'ro', + isa => 'Str', + default => 'file.dat', + cmd_flag => 'f', + ); + + has 'cow' => ( + metaclass => 'Getopt', + is => 'ro', + isa => 'Str', + default => 'moo', + cmd_aliases => [qw/ moocow m c /], + ); + + has 'horse' => ( + metaclass => 'MooseX::Getopt::Meta::Attribute', + is => 'ro', + isa => 'Str', + default => 'bray', + cmd_flag => 'horsey', + cmd_aliases => 'x', + ); + + has 'length' => ( + is => 'ro', + isa => 'Int', + default => 24 + ); + + has 'verbose' => ( + is => 'ro', + isa => 'Bool', + ); + + has 'libs' => ( + is => 'ro', + isa => 'ArrayRef', + default => sub { [] }, + ); + + has 'details' => ( + is => 'ro', + isa => 'HashRef', + default => sub { {} }, + ); + + has '_private_stuff' => ( + is => 'ro', + isa => 'Int', + default => 713 + ); + + has '_private_stuff_cmdline' => ( + metaclass => 'MooseX::Getopt::Meta::Attribute', + is => 'ro', + isa => 'Int', + default => 832, + cmd_flag => 'p', + ); + +} + +{ + my $app = App->new_with_options(argv => [ '--verbose', '--length', 50 ]); + # TEST + isa_ok($app, 'App'); + + # TEST + ok($app->verbose, '... verbosity is turned on as expected'); + # TEST + is($app->length, 50, '... length is 50 as expected'); + # TEST + is($app->data, 'file.dat', '... data is file.dat as expected'); + # TEST + is_deeply($app->libs, [], '... libs is [] as expected'); + # TEST + is_deeply($app->details, {}, '... details is {} as expected'); +} +