Skip to content

Instantly share code, notes, and snippets.

@zoffixznet
Created January 12, 2016 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoffixznet/4a623b529d2f52e833e3 to your computer and use it in GitHub Desktop.
Save zoffixznet/4a623b529d2f52e833e3 to your computer and use it in GitHub Desktop.
unit module Class::Descendants:ver<1.001001>;
sub descendants ($name) is export {
return @(
|fetch-descendants($name, ::GLOBAL.WHO),
|fetch-descendants($name, ::CORE.WHO),
)
}
sub fetch-descendants ($name, $ns, $prefix = '') {
my @descendants;
for $ns.keys {
my $key = $prefix ~ $_;
try my @parents = ::($key).^parents: :all;
@descendants.push: $key if $key ⊆ @parents;
say "$key [$_]"; say $ns{$_}.WHAT;
next unless $ns{$_}.WHAT;
@descendants.append: fetch-descendants $name, $ns{$_}, $key ~ '::'
if $ns{$_}.keys;
}
return @descendants.unique;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment