From: Stevan Little Date: Sun, 30 Dec 2007 21:51:48 +0000 (+0000) Subject: fixing sartaks bug X-Git-Tag: 0_35~42 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e7c06c1e1147b603a85d1f7588eb3a05b3ff9dc8;p=gitmo%2FMoose.git fixing sartaks bug --- diff --git a/Changes b/Changes index bfa15cf..c3c5587 100644 --- a/Changes +++ b/Changes @@ -1,7 +1,13 @@ Revision history for Perl extension Moose 0.34 - ~~ some doc fixes ~~ + ~~ more misc. doc fixes ~~ + + * Moose::Meta::Method::Accessor + - fixed bug when passing a list of values to + an accessor would get (incorrectly) ignored. + Thanks to Sartak for finding this ;) + - added tests for this (Sartak again) 0.33 Fri. Dec. 14, 2007 !! Moose now loads 2 x faster !! diff --git a/lib/Moose/Meta/Method/Accessor.pm b/lib/Moose/Meta/Method/Accessor.pm index e70cba1..a615ccc 100644 --- a/lib/Moose/Meta/Method/Accessor.pm +++ b/lib/Moose/Meta/Method/Accessor.pm @@ -6,7 +6,7 @@ use warnings; use Carp 'confess'; -our $VERSION = '0.08'; +our $VERSION = '0.09'; our $AUTHORITY = 'cpan:STEVAN'; use base 'Moose::Meta::Method', @@ -24,7 +24,7 @@ sub generate_accessor_method_inline { my $code = 'sub { ' . "\n" . $self->_inline_pre_body(@_) . "\n" - . 'if (scalar(@_) == 2) {' . "\n" + . 'if (scalar(@_) >= 2) {' . "\n" . $self->_inline_copy_value . "\n" . $self->_inline_check_required . "\n" . $self->_inline_check_coercion . "\n" diff --git a/t/020_attributes/013_attr_dereference_test.t b/t/020_attributes/013_attr_dereference_test.t index bc11931..903134b 100644 --- a/t/020_attributes/013_attr_dereference_test.t +++ b/t/020_attributes/013_attr_dereference_test.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 9; +use Test::More tests => 12; use Test::Exception; BEGIN { @@ -55,4 +55,29 @@ BEGIN { [], '... got the right dereferenced value' ); -} \ No newline at end of file +} + +{ + package AutoDeref; + use Moose; + + has 'bar' => ( + is => 'rw', + isa => 'ArrayRef[Int]', + auto_deref => 1, + ); +} + +{ + my $autoderef = AutoDeref->new; + + dies_ok { + $autoderef->bar(1, 2, 3); + } '... its auto-de-ref-ing, not auto-en-ref-ing'; + + lives_ok { + $autoderef->bar([ 1, 2, 3 ]) + } '... set the results of bar correctly'; + + is_deeply [ $autoderef->bar ], [ 1, 2, 3 ], '... auto-dereffed correctly'; +} diff --git a/t/040_type_constraints/011_container_type_constraint.t b/t/040_type_constraints/011_container_type_constraint.t index 829d96f..9e76ea0 100644 --- a/t/040_type_constraints/011_container_type_constraint.t +++ b/t/040_type_constraints/011_container_type_constraint.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 25; +use Test::More tests => 22; use Test::Exception; BEGIN { @@ -64,21 +64,5 @@ ok(!$array_of_array_of_ints->check( [[ 1, 2, 3 ], [ qw/foo bar/ ]] ), '... [[ 1, 2, 3 ], [ qw/foo bar/ ]] failed successfully'); -{ - package AutoDeref; - use Moose; - use Moose::Util::TypeConstraints; - has 'bar' => ( - is => 'rw', - isa => 'ArrayRef[Int]', - auto_deref => 1, - ); -} - -my $autoderef = AutoDeref->new; -lives_ok { $autoderef->bar(1, 2, 3) }; -is_deeply [ $autoderef->bar ], [1, 2, 3]; - -dies_ok { $autoderef->bar(1, "foo", 3) };