From: Todd Hepler Date: Wed, 21 May 2008 20:08:11 +0000 (+0000) Subject: make has [...] => (...); work on a role X-Git-Tag: 0_55~155 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1580432f71e8d42a4070f19f15e94a062300fb47;p=gitmo%2FMoose.git make has [...] => (...); work on a role --- diff --git a/lib/Moose/Role.pm b/lib/Moose/Role.pm index 0f2ef34..f916430 100644 --- a/lib/Moose/Role.pm +++ b/lib/Moose/Role.pm @@ -75,8 +75,11 @@ use Moose::Util::TypeConstraints; has => sub { my $meta = _find_meta(); return Class::MOP::subname('Moose::Role::has' => sub ($;%) { - my ($name, %options) = @_; - $meta->add_attribute($name, %options) + my $name = shift; + confess 'Usage: has \'name\' => ( key => value, ... )' if @_ == 1; + my %options = @_; + my $attrs = ( ref($name) eq 'ARRAY' ) ? $name : [ ($name) ]; + $meta->add_attribute( $_, %options ) for @$attrs; }); }, before => sub { diff --git a/t/020_attributes/012_misc_attribute_tests.t b/t/020_attributes/012_misc_attribute_tests.t index cdb3342..24e3f70 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 => 42; +use Test::More tests => 44; use Test::Exception; BEGIN { @@ -87,6 +87,28 @@ BEGIN { { { + package Test::Arrayref::RoleAttributes::Role; + use Moose::Role; + + has [qw(foo bar baz)] => ( + is => 'rw', + ); + + } + { + package Test::Arrayref::RoleAttributes; + use Moose; + with 'Test::Arrayref::RoleAttributes::Role'; + } + + my $test = Test::Arrayref::RoleAttributes->new; + isa_ok($test, 'Test::Arrayref::RoleAttributes'); + can_ok($test, qw(foo bar baz)); + +} + +{ + { package Test::UndefDefault::Attributes; use Moose;