From: michaelr Date: Wed, 13 May 2009 19:23:45 +0000 (-0500) Subject: added check for an even number of options to 'has' X-Git-Tag: 0.80~85 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=db532c7d56babb46064f82637256ffbd5a15af55;p=gitmo%2FMoose.git added check for an even number of options to 'has' --- diff --git a/lib/Moose.pm b/lib/Moose.pm index e5880c2..40fc9e2 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -67,7 +67,7 @@ sub has { my $name = shift; Moose->throw_error('Usage: has \'name\' => ( key => value, ... )') - if @_ == 1; + if @_ % 2 == 1; my %options = ( definition_context => _caller_info(), @_ ); my $attrs = ( ref($name) eq 'ARRAY' ) ? $name : [ ($name) ]; diff --git a/t/020_attributes/012_misc_attribute_tests.t b/t/020_attributes/012_misc_attribute_tests.t index ac3372b..ad66b63 100644 --- a/t/020_attributes/012_misc_attribute_tests.t +++ b/t/020_attributes/012_misc_attribute_tests.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 47; +use Test::More tests => 48; use Test::Exception; @@ -262,3 +262,15 @@ lives_ok { OutOfClassTest->can('has')->('bar'); } 'create attr via can'; ok(OutOfClassTest->meta->get_attribute('foo'), 'attr created from sub call'); ok(OutOfClassTest->meta->get_attribute('bar'), 'attr created from can'); + + +{ + { + package Foo; + use Moose; + + ::throws_ok { has 'foo' => ( 'ro', isa => 'Str' ) } + qr/^Usage/, 'has throws error with odd number of attribute options'; + } + +}