Browse files

basic implementation of "handles" on methods

  • Loading branch information...
1 parent e2eb219 commit bdd23f2b751d6a77600d57e3b6aed01177e2f395 @moritz moritz committed Oct 13, 2012
Showing with 12 additions and 0 deletions.
  1. +12 −0 src/core/traits.pm
View
12 src/core/traits.pm
@@ -270,6 +270,18 @@ multi trait_mod:<handles>(Attribute:D $target, $thunk) {
$target.set_handles($thunk());
}
+multi sub trait_mod:<handles>(Method:D $m, &thunk) {
+ my $pkg := $m.signature.params[0].type;
+ my $call_name := nqp::unbox_s($m.name);
+ for thunk() -> $meth_name {
+ my $meth := method (|c) is rw {
+ self."$call_name"()."$meth_name"(|c);
+ }
+ $meth.set_name($meth_name);
+ $pkg.HOW.add_method($pkg, $meth_name, $meth);
+ }
+}
+
proto trait_mod:<will>(|) { * }
multi trait_mod:<will>(Attribute $attr, Block :$build!) {
$attr.set_build($build)

0 comments on commit bdd23f2

Please sign in to comment.