From: Jesse Luehrs Date: Thu, 24 Jun 2010 18:36:46 +0000 (-0500) Subject: add a applied_attribute_metaclass to roles X-Git-Tag: 1.9900~57 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d037bb6268369b528f70e007d599ba8717aa2768;p=gitmo%2FMoose.git add a applied_attribute_metaclass to roles this way, roles don't just automatically absorb the class's attribute metaclass (at the moment, using MooseX::FollowPBP in a class can just break a role that doesn't use it). also, allows this to be customized by metarole, since you almost always want to be modifying the eventual class attribute, not the role attribute --- diff --git a/lib/Moose/Meta/Role.pm b/lib/Moose/Meta/Role.pm index 4803d3f..1f73a09 100644 --- a/lib/Moose/Meta/Role.pm +++ b/lib/Moose/Meta/Role.pm @@ -157,6 +157,12 @@ $META->add_attribute( default => 'Moose::Meta::Role::Application::ToInstance', ); +$META->add_attribute( + 'applied_attribute_metaclass', + reader => 'applied_attribute_metaclass', + default => 'Moose::Meta::Attribute', +); + # More or less copied from Moose::Meta::Class sub initialize { my $class = shift; @@ -196,6 +202,7 @@ sub reinitialize { application_to_class_class application_to_role_class application_to_instance_class + applied_attribute_metaclass ); } diff --git a/lib/Moose/Meta/Role/Application/ToClass.pm b/lib/Moose/Meta/Role/Application/ToClass.pm index 8954cd0..a7489ba 100644 --- a/lib/Moose/Meta/Role/Application/ToClass.pm +++ b/lib/Moose/Meta/Role/Application/ToClass.pm @@ -129,7 +129,7 @@ sub check_required_attributes { sub apply_attributes { my ($self, $role, $class) = @_; - my $attr_metaclass = $class->attribute_metaclass; + my $attr_metaclass = $role->applied_attribute_metaclass; foreach my $attribute_name ($role->get_attribute_list) { # it if it has one already