Skip to content

Instantly share code, notes, and snippets.

Created April 28, 2012 13:45
Show Gist options
  • Save anonymous/2519182 to your computer and use it in GitHub Desktop.
Save anonymous/2519182 to your computer and use it in GitHub Desktop.
signal-trait-golf.p6
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