Oop 反思NQP角色
从中,我发现了Oop 反思NQP角色,oop,mixins,introspection,raku,nqp,Oop,Mixins,Introspection,Raku,Nqp,从中,我发现了类型。^roles,其中包括组成类型的所有角色。它适用于所有地方,但如果某个地方有NQP角色,它将无法打印: say Cursor.^roles# OUTPUT: «No such method 'gist' for invocant of type 'NQPMatchRole'. Did you mean 'ast'? in block <unit> » 我是否可以假设NQP角色遵循与Perl 6相同的元模型,并且我至少可以使用^name?是否有一种更通用
类型。^roles
,其中包括组成类型的所有角色。它适用于所有地方,但如果某个地方有NQP角色,它将无法打印:
say Cursor.^roles# OUTPUT: «No such method 'gist' for invocant of type 'NQPMatchRole'. Did you mean 'ast'? in block <unit> »
我是否可以假设NQP角色遵循与Perl 6相同的元模型,并且我至少可以使用
^name
?是否有一种更通用的方式来打印所有角色,包括Perl 6和NQP角色?我现在记不起我在哪里读到过它,但你的观察是对的:NQP toe对象确实遵循元模型。至少大部分是这样。
my @cursor-roles = Cursor.^roles; print $_.^name for @cursor-roles ; # OUTPUT: «NQPMatchRole»