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.
$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;