From: Jonathan Rockway Date: Tue, 13 May 2008 08:17:15 +0000 (+0000) Subject: use correct metaclass when applying roles to instances X-Git-Tag: 0_55~177 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c87f0c7f501b1487299a59cb1dbe5297c6462537;p=gitmo%2FMoose.git use correct metaclass when applying roles to instances Instead of always applying the role with Moose::Meta::Object, determine the object's metaclass and use that to apply the role. This makes it possible to apply roles to instances of classes that have a custom metaclass. --- diff --git a/lib/Moose/Meta/Role/Application/ToInstance.pm b/lib/Moose/Meta/Role/Application/ToInstance.pm index f0ed1a7..fe23910 100644 --- a/lib/Moose/Meta/Role/Application/ToInstance.pm +++ b/lib/Moose/Meta/Role/Application/ToInstance.pm @@ -29,7 +29,8 @@ sub apply { $class = $ANON_CLASSES{$anon_role_key}; } else { - $class = Moose::Meta::Class->create_anon_class( + my $obj_meta = eval { $object->meta } || 'Moose::Meta::Class'; + $class = $obj_meta->create_anon_class( superclasses => [ blessed($object) ] ); $ANON_CLASSES{$anon_role_key} = $class;