Fix metaclass compatibility
gfx [Mon, 8 Mar 2010 09:29:40 +0000 (18:29 +0900)]
lib/Mouse/Meta/Module.pm
lib/Mouse/Meta/Role/Composite.pm
t/001_mouse/061-metaclass-compatibility.t

index 68f100f..419d347 100755 (executable)
@@ -231,7 +231,7 @@ sub create {
     Scalar::Util::weaken $METAS{$package_name}
         if $mortal;
 
-    $meta->add_method(meta => sub{
+    $meta->add_method(meta => sub {
         $self->initialize(ref($_[0]) || $_[0]);
     });
 
index 5a53e53..c22aef3 100644 (file)
@@ -16,16 +16,18 @@ sub add_method {
         return;
     }
 
-    if($method_name ne 'meta'){
+    if($method_name eq 'meta'){
+        $self->SUPER::add_method($method_name => $code);
+    }
+    else{
+        # no need to add a subroutine to the stash
         my $roles = $self->{composed_roles_by_method}{$method_name} ||= [];
         push @{$roles}, $role;
         if(@{$roles} > 1){
             $self->{conflicting_methods}{$method_name}++;
         }
+        $self->{methods}{$method_name} = $code;
     }
-
-    $self->{methods}{$method_name} = $code;
-    # no need to add a subroutine to the stash
     return;
 }
 
index 3b0e128..9548c31 100644 (file)
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 4;
+use Test::More;
 
 use Mouse::Util qw(does_role);
 
@@ -20,6 +20,11 @@ use Mouse::Util qw(does_role);
     use Mouse -traits => qw(BarTrait);
 
     extends qw(BaseClass);
+
+    package SubSubClass;
+    use Mouse;
+
+    extends qw(SubClass);
 }
 
 ok does_role(BaseClass->meta, 'FooTrait'), ' BaseClass->meta->does("FooTrait")';
@@ -28,3 +33,7 @@ ok!does_role(BaseClass->meta, 'BarTrait'), '!BaseClass->meta->does("BarTrait")';
 ok does_role(SubClass->meta,  'FooTrait'), 'SubClass->meta->does("FooTrait")';
 ok does_role(SubClass->meta,  'BarTrait'), 'SubClass->meta->does("BarTrait")';
 
+ok does_role(SubSubClass->meta,  'FooTrait'), 'SubSubClass->meta->does("FooTrait")';
+ok does_role(SubSubClass->meta,  'BarTrait'), 'SubSubClass->meta->does("BarTrait")';
+
+done_testing;