From: Dave Rolsky Date: Fri, 29 Oct 2010 21:31:45 +0000 (-0500) Subject: Fix error when array accessor delegation method is called with no arguments X-Git-Tag: 1.18~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8fc30049991bd3bde3251577ff3edf6633d3fc2e;p=gitmo%2FMoose.git Fix error when array accessor delegation method is called with no arguments --- diff --git a/lib/Moose/Meta/Method/Accessor/Native/Array/accessor.pm b/lib/Moose/Meta/Method/Accessor/Native/Array/accessor.pm index 99fbb84..97ea12e 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Array/accessor.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Array/accessor.pm @@ -71,8 +71,7 @@ sub _generate_method { return $code; } -# If we get one argument we won't check the argument count -sub _minimum_arguments {2} +sub _minimum_arguments {1} sub _maximum_arguments {2} no Moose::Role; diff --git a/lib/Moose/Meta/Method/Accessor/Native/Hash/accessor.pm b/lib/Moose/Meta/Method/Accessor/Native/Hash/accessor.pm index 9713a85..e7348ab 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Hash/accessor.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Hash/accessor.pm @@ -74,7 +74,6 @@ sub _generate_method { return $code; } -# If we get one argument we won't check the argument count sub _minimum_arguments {1} sub _maximum_arguments {2} diff --git a/t/070_native_traits/010_trait_array.t b/t/070_native_traits/010_trait_array.t index 3785904..8774ffa 100644 --- a/t/070_native_traits/010_trait_array.t +++ b/t/070_native_traits/010_trait_array.t @@ -227,6 +227,14 @@ sub run_tests { is( $obj->accessor( 1 => 97 ), 97, 'accessor returns new value' ); }, undef, 'accessor as writer lives' ); + like( + exception { + $obj->accessor; + }, + qr/Cannot call accessor without at least 1 argument/, + 'throws an error when accessor is called without arguments' + ); + is( $obj->get(1), 97, 'accessor set value at index 1'