Is there a way to get a list of all known types (builtin, defined, loaded, whatever) a Perl 6 program knows about? I don't have a particular task in mind, and this is a bit different than figuring out if a type I already know about has been defined.
This should do the trick:
.say for (|CORE::, |UNIT::, |OUTERS::, |MY::)
.grep({ .key eq .value.^name })
.map(*.key)
.unique
;
Perl 6 provides Pseudo-packages that allow indirect look-up of symbols that are declared/visible in different scopes. They can be accessed and iterated like Hashes.
CORE::
. LEXICAL::
would contain them all, but based on some experimentation that doesn't seems to be case and it looks like UNIT::
, OUTERS::
, and MY::
need to be searched to catch 'em all.The kind of symbols defined in those pseudo-packages include:
To get only the types, I grepped the ones where the symbol's declared name equals the name of its object type.
If you wanted only classes, you could add the following step:
.grep({ .value.HOW.^name eq 'Perl6::Metamodel::ClassHOW' })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With