From: Scott McWhirter Date: Thu, 5 Apr 2007 21:40:37 +0000 (+0000) Subject: Add ability to use an arrayref with has() to create multiple attributes with the... X-Git-Tag: 0_21~27 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f6e5456fb2a2e7c5808ef47572322b94e6bc8633;p=gitmo%2FMoose.git Add ability to use an arrayref with has() to create multiple attributes with the same options. --- diff --git a/lib/Moose.pm b/lib/Moose.pm index 22ee850..23f8b5b 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -92,8 +92,9 @@ use Moose::Util::TypeConstraints; has => sub { my $class = $CALLER; return subname 'Moose::has' => sub ($;%) { - my ($name, %options) = @_; - $class->meta->_process_attribute($name, %options); + my ($name, %options) = @_; + my $attrs = (ref($name) eq 'ARRAY') ? $name : [($name)]; + $class->meta->_process_attribute($_, %options) for @$attrs; }; }, before => sub { diff --git a/t/071_misc_attribute_tests.t b/t/071_misc_attribute_tests.t index 3849d64..bdab707 100644 --- a/t/071_misc_attribute_tests.t +++ b/t/071_misc_attribute_tests.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 6; +use Test::More tests => 8; use Test::Exception; BEGIN { @@ -67,3 +67,20 @@ BEGIN { $test->good_lazy_attr; } '... this does not work'; } + +{ + { + package Test::Arrayref::Attributes; + use Moose; + + has [qw(foo bar baz)] => ( + is => 'rw', + ); + + } + + my $test = Test::Arrayref::Attributes->new; + isa_ok($test, 'Test::Arrayref::Attributes'); + can_ok($test, qw(foo bar baz)); + +}