我有一个组成鼠标角色的 Moose 类。
package My::Moose::Class;
use Moose;
has 'mouse_obj' => (
is => 'ro',
does => 'NotMy::Mouse::Role',
);
package NotMy::Mouse::Role;
use Mouse::Role;
package NotMy::Mouse::Class;
use Mouse;
with 'NotMy::Mouse::Role';
这将得到一个错误,因为 Mouse 角色在 Moose 中未被识别为一种类型:
my $f = My::Moose::Class->new( mouse_obj => NotMy::Mouse::Class->new );
属性 (mouse_obj) 未通过类型约束,因为: 'NotMy::Mouse::Role' 的验证失败,值为 NotMy::Mouse::Class=HASH(0x23932dc) (not isa NotMy::Mouse::Role) at ...
有哪些方法可以在不将鼠标对象更改为 Moose 的情况下使其工作?