Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply first cut of handles method generator. Patch courtesy of maard++.
- Loading branch information
Showing
2 changed files
with
21 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); } | ||
} | ||
} | ||
} |