Skip to content

Instantly share code, notes, and snippets.

@gfldex
Created June 20, 2016 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gfldex/51bc1f2d2ec4d5ac3ee27c9530acca4d to your computer and use it in GitHub Desktop.
Save gfldex/51bc1f2d2ec4d5ac3ee27c9530acca4d to your computer and use it in GitHub Desktop.
use v6;
class L {
method log($l, $s) { say "$l: $s" };
method FALLBACK($name, $s) {
my $c_name = $name;
if ($name ~~ / log (\d) /) {
my $level = $0;
self.^add_method($name, method (Str $msg) {
self.log($level, $msg)
});
self.^compose();
self."log$level"($s)
}
}
};
my $log = L.new;
$log.log0("foo");
$log.log1("bar");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment