Make sure roles are applied to right metaclass
[gitmo/MooseX-ClassAttribute.git] / lib / MooseX / ClassAttribute / Trait / Application / ToRole.pm
index aea2dab..babdbff 100644 (file)
@@ -3,8 +3,6 @@ package MooseX::ClassAttribute::Trait::Application::ToRole;
 use strict;
 use warnings;
 
-our $VERSION   = '0.13';
-
 use Moose::Util::MetaRole;
 use MooseX::ClassAttribute::Trait::Application::ToClass;
 
@@ -13,12 +11,13 @@ use Moose::Role;
 
 with 'MooseX::ClassAttribute::Trait::Application';
 
-sub _apply_class_attributes {
+around apply => sub {
+    my $orig  = shift;
     my $self  = shift;
     my $role1 = shift;
     my $role2 = shift;
 
-    $role2 = Moose::Util::MetaRole::apply_metaclass_roles(
+    $role2 = Moose::Util::MetaRole::apply_metaroles(
         for            => $role2,
         role_metaroles => {
             role => ['MooseX::ClassAttribute::Trait::Role'],
@@ -29,6 +28,14 @@ sub _apply_class_attributes {
         },
     );
 
+    $self->$orig( $role1, $role2 );
+};
+
+sub _apply_class_attributes {
+    my $self  = shift;
+    my $role1 = shift;
+    my $role2 = shift;
+
     foreach my $attribute_name ( $role1->get_class_attribute_list() ) {
         if (   $role2->has_class_attribute($attribute_name)
             && $role2->get_class_attribute($attribute_name)
@@ -50,32 +57,19 @@ sub _apply_class_attributes {
 
 1;
 
+# ABSTRACT: A trait that supports applying class attributes to roles
+
 __END__
 
 =pod
 
-=head1 NAME
-
-MooseX::ClassAttribute::Trait::Application::ToRole - A trait that supports applying class attributes to roles
-
 =head1 DESCRIPTION
 
 This trait is used to allow the application of roles containing class
 attributes to roles.
 
-=head1 AUTHOR
-
-Dave Rolsky, C<< <autarch@urth.org> >>
-
 =head1 BUGS
 
 See L<MooseX::ClassAttribute> for details.
 
-=head1 COPYRIGHT & LICENSE
-
-Copyright 2007-2010 Dave Rolsky, All Rights Reserved.
-
-This program is free software; you can redistribute it and/or modify
-it under the same terms as Perl itself.
-
 =cut