3

From this question in StackOverflow, I discovered Type.^roles, which includes all roles that are composed into a type. It works all over the place, but it fails to print if there are NQP roles somewhere:

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

There's no method gist or Str. However, ^name seems to work:

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

Can I assume NQP roles follow the same metamodel as Perl 6, and I can at least use the ^name? Is there a more general way of printing all roles, including both Perl 6 and NQP roles?

jjmerelo
  • 22,578
  • 8
  • 40
  • 86
  • 1
    Can't currently recall where I read about it, but you're right in your observation: NQP toe objects do follow the Metamodel. At least most of it. – Vadim Belman Jan 22 '19 at 06:15

0 Answers0