Created
April 28, 2012 13:45
-
-
Save anonymous/2519182 to your computer and use it in GitHub Desktop.
signal-trait-golf.p6
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
use v6; | |
role Signal { | |
has @.slots; # a nice list of callbacks (that are methods) | |
multi method connect(Routine $r){ | |
@.slots.push($r); | |
} | |
} | |
multi trait_mod:<is>(Routine $r, :$signal!){ | |
$r does Signal; | |
# HERE BE DRAGONS | |
# say $r.slots.elems; # uncomment this line and it works | |
sub handle_call(|$args){ | |
for $r.slots -> $method { | |
$method(|$args); | |
} | |
} | |
$r.wrap(&handle_call); | |
} | |
multi sub connect(Signal $s, Routine $r){ | |
$s.connect($r); | |
} | |
sub bare_slot { say "bare_slot called" } | |
sub bare_signal_exit is signal {} | |
connect(&bare_signal_exit, &bare_slot); | |
bare_signal_exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment