The excellent 2011 Advent of Raku post Meta-programming: what, why and how provides a few clear examples of using EXPORTHOW
to create a declarator that acts like class
. Here's the first:
my class SingleInheritanceClassHOW
is Metamodel::ClassHOW
{
method add_parent(Mu $obj, Mu $parent) {
if +self.parents($obj, :local) > 0 {
die "Multiple inheritance is forbidden!";
}
callsame;
}
}
my module EXPORTHOW { }
EXPORTHOW.WHO.<class> = SingleInheritanceClassHOW;
Is there a way to do something similar for a declarator that acts like sub
(that is, that allows the use to supply a signature and block, rather than allowing the user to supply attributes and methods)? The metaclass of a Sub
is ClassHOW
, so it seems that something similar should be possible, but I'm not seeing a way to do so.