handle fixing when the child class already does all necessary roles
Jesse Luehrs [Thu, 10 Jun 2010 23:25:06 +0000 (18:25 -0500)]
lib/Moose/Meta/Class.pm
t/050_metaclasses/054_metaclass_compat_no_fixing_bug.t [new file with mode: 0644]

index 4f2a829..20874bf 100644 (file)
@@ -525,6 +525,14 @@ sub _reconcile_roles_for_metaclass {
     my @role_differences = $self->_role_differences(
         $class_meta_name, $super_meta_name,
     );
+
+    # handle the case where we need to fix compatibility between a class and
+    # its parent, but all roles in the class are already also done by the
+    # parent
+    # see t/050/054.t
+    return Class::MOP::class_of($super_meta_name)
+        unless @role_differences;
+
     return Moose::Meta::Class->create_anon_class(
         superclasses => [$super_meta_name],
         roles        => \@role_differences,
diff --git a/t/050_metaclasses/054_metaclass_compat_no_fixing_bug.t b/t/050_metaclasses/054_metaclass_compat_no_fixing_bug.t
new file mode 100644 (file)
index 0000000..6190faa
--- /dev/null
@@ -0,0 +1,46 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+use Test::Exception;
+
+{
+    package Foo::Meta::Constructor1;
+    use Moose::Role;
+}
+
+{
+    package Foo::Meta::Constructor2;
+    use Moose::Role;
+}
+
+{
+    package Foo;
+    use Moose;
+    Moose::Util::MetaRole::apply_metaroles(
+        for             => __PACKAGE__,
+        class_metaroles => { constructor => ['Foo::Meta::Constructor1'] },
+    );
+}
+
+{
+    package Foo::Sub;
+    use Moose;
+    Moose::Util::MetaRole::apply_metaroles(
+        for             => __PACKAGE__,
+        class_metaroles => { constructor => ['Foo::Meta::Constructor2'] },
+    );
+    extends 'Foo';
+}
+
+{
+    package Foo::Sub::Sub;
+    use Moose;
+    Moose::Util::MetaRole::apply_metaroles(
+        for             => __PACKAGE__,
+        class_metaroles => { constructor => ['Foo::Meta::Constructor2'] },
+    );
+    ::lives_ok { extends 'Foo::Sub' } "doesn't try to fix if nothing is needed";
+}
+
+done_testing;