Skip to content

Commit

Permalink
Apply first cut of handles method generator. Patch courtesy of maard++.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Jun 19, 2010
1 parent 406d85f commit edb8be9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions build/Makefile.in
Expand Up @@ -171,6 +171,7 @@ CORE_SOURCES = \
src/core/traits.pm \
src/core/metaops.pm \
src/core/operators.pm \
src/glue/handles.pm \
src/glue/subset.pm \
src/cheats/trait-export.pm \
src/cheats/num.pm \
Expand Down
20 changes: 20 additions & 0 deletions src/glue/handles.pm
@@ -0,0 +1,20 @@
our sub add_handles_method_helper($metaclass, $attr, $meth-name, $meth-rename = $meth-name) {
$metaclass.add_method($metaclass, $meth-name, (method (|$c) {
pir::getattribute__PPS(self, $attr)."$meth-rename"(|$c);
}).clone() );
}

our sub add_handles_method($metaclass, $attr_name, $expr) {
for ($expr) -> $x {
given $x {
when Str { add_handles_method_helper($metaclass, $attr_name, $x); }
when Parcel {
for $x.list -> $x { add_handles_method_helper($metaclass, $attr_name, $x); }
}
when Pair {
add_handles_method_helper($metaclass, $attr_name, $x.key, $x.value);
}
default { die sprintf("add_handles_method can't handle %s in list", $x.WHAT); }
}
}
}

0 comments on commit edb8be9

Please sign in to comment.