Created
August 26, 2010 20:04
-
-
Save timbunce/552139 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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