Created
June 21, 2023 20:30
-
-
Save gfldex/c6b3dc2f6c648907788d9c2f67508e35 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
multi sub trait_mod:<is>(Routine \r, :$renamed) { | |
role RenamedMulti[$name] { | |
method name { $name } | |
} | |
use nqp; | |
my Mu $do := nqp::getattr(nqp::decont(r), ForeignCode, '$!do'); | |
nqp::setcodename($do, nqp::decont_s($renamed)); | |
r does RenamedMulti[$renamed] | |
} | |
proto sub foo(|) is renamed<foo-proto> { * } | |
multi sub foo(Int $) is renamed<inter> { say &?ROUTINE.name } | |
multi sub foo(Str $) is renamed<stringer> { say &?ROUTINE.name } | |
multi sub foo(Failure) is renamed<failer> { fail('oi‽') } | |
foo(42); | |
foo('answer'); | |
foo(Failure); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OUTPUT: