ignore composite roles during role reconciliation
Jesse Luehrs [Thu, 7 Oct 2010 23:11:22 +0000 (18:11 -0500)]
lib/Moose/Util.pm
t/060_compat/005_composite_metaroles.t [new file with mode: 0755]

index ac48606..74ce8b3 100644 (file)
@@ -322,16 +322,20 @@ sub _reconcile_roles_for_metaclass {
 
 sub _role_differences {
     my ($class_meta_name, $super_meta_name) = @_;
-    my @super_role_metas = $super_meta_name->meta->can('calculate_all_roles_with_inheritance')
-                         ? $super_meta_name->meta->calculate_all_roles_with_inheritance
-                         : $super_meta_name->meta->can('calculate_all_roles')
-                         ? $super_meta_name->meta->calculate_all_roles
-                         : ();
-    my @role_metas       = $class_meta_name->meta->can('calculate_all_roles_with_inheritance')
-                         ? $class_meta_name->meta->calculate_all_roles_with_inheritance
-                         : $class_meta_name->meta->can('calculate_all_roles')
-                         ? $class_meta_name->meta->calculate_all_roles
-                         : ();
+    my @super_role_metas
+        = grep { !$_->isa('Moose::Meta::Role::Composite') }
+               $super_meta_name->meta->can('calculate_all_roles_with_inheritance')
+                   ? $super_meta_name->meta->calculate_all_roles_with_inheritance
+                   : $super_meta_name->meta->can('calculate_all_roles')
+                   ? $super_meta_name->meta->calculate_all_roles
+                   : ();
+    my @role_metas
+        = grep { !$_->isa('Moose::Meta::Role::Composite') }
+               $class_meta_name->meta->can('calculate_all_roles_with_inheritance')
+                   ? $class_meta_name->meta->calculate_all_roles_with_inheritance
+                   : $class_meta_name->meta->can('calculate_all_roles')
+                   ? $class_meta_name->meta->calculate_all_roles
+                   : ();
     my @differences;
     for my $role_meta (@role_metas) {
         push @differences, $role_meta
diff --git a/t/060_compat/005_composite_metaroles.t b/t/060_compat/005_composite_metaroles.t
new file mode 100755 (executable)
index 0000000..570ce30
--- /dev/null
@@ -0,0 +1,45 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+use Test::Moose;
+
+{
+    package Foo::Role;
+    use Moose::Role;
+}
+
+{
+    package Bar::Role;
+    use Moose::Role;
+}
+
+{
+    package Parent;
+    use Moose;
+    Moose::Util::MetaRole::apply_metaroles(
+        for => __PACKAGE__,
+        class_metaroles => { class => ['Foo::Role'] },
+    );
+}
+
+{
+    package Child;
+    use Moose;
+    Moose::Util::MetaRole::apply_metaroles(
+        for => __PACKAGE__,
+        class_metaroles => { class => ['Foo::Role', 'Bar::Role'] },
+    );
+    ::lives_ok { extends 'Parent' };
+}
+
+with_immutable {
+    isa_ok('Child', 'Parent');
+    isa_ok(Child->meta, Parent->meta->_real_ref_name);
+    does_ok(Parent->meta, 'Foo::Role');
+    does_ok(Child->meta, 'Foo::Role');
+    does_ok(Child->meta, 'Bar::Role');
+} 'Parent', 'Child';
+
+done_testing;