3

StackOverflow 中的这个问题中,我发现了Type.^roles,其中包括组成一个类型的所有角色。它在所有地方都有效,但如果某处有 NQP 角色,它就无法打印:

 say Cursor.^roles# OUTPUT: «No such method 'gist' for invocant of type 'NQPMatchRole'. Did you mean 'ast'?␤  in block <unit> ␤␤»

没有方法gistStr. 但是,^name似乎有效:

my @cursor-roles = Cursor.^roles; print $_.^name for @cursor-roles ; # OUTPUT: «NQPMatchRole»

我可以假设 NQP 角色遵循与 Perl 6 相同的元模型,并且我至少可以使用^name? 是否有更通用的打印所有角色的方法,包括 Perl 6 和 NQP 角色?

4

0 回答 0