From: gfx Date: Mon, 8 Mar 2010 09:29:40 +0000 (+0900) Subject: Fix metaclass compatibility X-Git-Tag: 0.50_08~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a062712d30b1985a9a084517a2680be70e9fb727;p=gitmo%2FMouse.git Fix metaclass compatibility --- diff --git a/lib/Mouse/Meta/Module.pm b/lib/Mouse/Meta/Module.pm index 68f100f..419d347 100755 --- a/lib/Mouse/Meta/Module.pm +++ b/lib/Mouse/Meta/Module.pm @@ -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]); }); diff --git a/lib/Mouse/Meta/Role/Composite.pm b/lib/Mouse/Meta/Role/Composite.pm index 5a53e53..c22aef3 100644 --- a/lib/Mouse/Meta/Role/Composite.pm +++ b/lib/Mouse/Meta/Role/Composite.pm @@ -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; } diff --git a/t/001_mouse/061-metaclass-compatibility.t b/t/001_mouse/061-metaclass-compatibility.t index 3b0e128..9548c31 100644 --- a/t/001_mouse/061-metaclass-compatibility.t +++ b/t/001_mouse/061-metaclass-compatibility.t @@ -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;