From: Tomas Doran Date: Tue, 11 May 2010 15:25:40 +0000 (+0200) Subject: 'Fix' has '+attr' in roles by exploding earlier. X-Git-Tag: 1.04~14 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=576cd474fc09bba92843e299a33dd2634629a930;p=gitmo%2FMoose.git 'Fix' has '+attr' in roles by exploding earlier. This stops us from allowing you to compose roles with has '+attr', which latter fail when composed onto a class, by exploding earlier (i.e. at the point which the attribute is added) It seems like there is some duplicate functionality in Moose::Meta::Class' process_attribute / add_attribute methods, possible candidate for later refactoring? --- diff --git a/Changes b/Changes index 1eecc22..339d178 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,11 @@ Also see Moose::Manual::Delta for more details of, and workarounds for, noteworthy changes. + [BUG FIXES] + + * Fix has '+attr' in Roles to explode immediately, rather than when the role + is applied to a class. + 1.03 Thu, May 06, 2010 [NEW FEATURES] diff --git a/lib/Moose/Meta/Role.pm b/lib/Moose/Meta/Role.pm index 742ae7c..adabdeb 100644 --- a/lib/Moose/Meta/Role.pm +++ b/lib/Moose/Meta/Role.pm @@ -197,6 +197,9 @@ sub add_attribute { my $class = ref $_[0]; Moose->throw_error( "Cannot add a $class as an attribute to a role" ); } + elsif (!blessed($_[0]) && $_[0] =~ /^\+(.*)/) { + Moose->throw_error( "has '+attr' is not supported in roles" ); + } return $self->SUPER::add_attribute(@_); } diff --git a/t/030_roles/017_extending_role_attrs.t b/t/030_roles/017_extending_role_attrs.t index b475be3..c34d9c9 100644 --- a/t/030_roles/017_extending_role_attrs.t +++ b/t/030_roles/017_extending_role_attrs.t @@ -172,4 +172,16 @@ is_deeply($quux->quux, ["hi"], "... still has the old ArrayRef value"); } "or add new types to the union"; } +{ + package Role::With::PlusAttr; + use Moose::Role; + + with 'Foo::Role'; + + ::throws_ok { + has '+bar' => ( is => 'ro' ); + } qr/has '\+attr' is not supported in roles/, + "Test has '+attr' in roles explodes"; +} + done_testing;