Skip to content

Instantly share code, notes, and snippets.

@timbunce
Created August 26, 2010 20:04
Show Gist options
  • Save timbunce/552139 to your computer and use it in GitHub Desktop.
Save timbunce/552139 to your computer and use it in GitHub Desktop.
role R {
method m() { say 42 }
}
class C does R {
}
my $x = C.new;
log-calls($x, R);
my @log;
sub log-calls($obj, Role $r) {
my $wrapper = RoleHOW.new;
for $r.^methods -> $m {
$wrapper.^add_method($m.name, method (|$c) {
push @log, "called $m.name";
nextsame;
});
}
$obj does $wrapper.^compose();
}
$x.m();
say @log.perl;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment