Created
June 20, 2016 14:41
-
-
Save gfldex/51bc1f2d2ec4d5ac3ee27c9530acca4d to your computer and use it in GitHub Desktop.
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
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