I'm trying to programmatically delegate via code, mainly to not have to keep track of a "handles" trait with lots of method names.
So I want to try and add all of the methods in SOUP::Server
to the first attribute in my SOUP::Test::Server
class.
I've come up with this bit of code, but it's not working:
sub getMethodNames(Mu \o) {
o.^methods( :local )
.grep({
.name ne <BEGIN BUILD BUILDALL DESTROY TWEAK>.any &&
.package.^name eq o.^name
})
.map( *.name )
.unique
}
trait_mod:<handles>(
self.^attributes[0],
sub { getMethodNames(SOUP::Server) }
);
self.^attributes[0].apply_handles( SOUP::Test::Server );
This is being done at run time. Is it too late in the object lifetime for this to work?
Aha!
Thanks to @dakkar on #raku, this looks to be the best solution:
Will delegate all methods of class A to class B. Thanks again, @dakkar++