Last active
February 10, 2021 23:23
-
-
Save gfldex/31f7bd6a393ee3ef20db96ce1d5468f3 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
class InterceptHOW is Metamodel::ClassHOW { | |
method publish_method_cache(|) { } | |
} | |
sub ipry(Mu $the-object is raw) { | |
# use InterceptAllMethods; | |
# class Interceptor { | |
# has Mu $!the-object; | |
# method ^find_method(Mu \type, Str $name) { | |
# my method (Mu \SELF:) is raw { | |
# use nqp; | |
# my $the-object := nqp::getattr(SELF, Interceptor, '$!the-object'); | |
# nqp::getattr($the-object, $the-object.WHAT, '$!' ~ $name) | |
# } | |
# } | |
# } | |
# | |
my \Interceptor = InterceptHOW.new_type(:name<Interceptor>); | |
Interceptor.^add_attribute(Attribute.new(:name<$!the-object>, :type(Mu), :package(Interceptor))); | |
Interceptor.^add_meta_method('find_method', | |
my method find_method(Mu \type, Str $name) { | |
# say „looking for $name“; | |
my method (Mu \SELF:) is raw { | |
use nqp; | |
my $the-object := nqp::getattr(SELF, Interceptor, '$!the-object'); | |
nqp::getattr($the-object, $the-object.WHAT, '$!' ~ $name) | |
} | |
}); | |
Interceptor.^compose; | |
use nqp; | |
nqp::p6bindattrinvres(nqp::create(Interceptor), Interceptor, '$!the-object', $the-object); | |
} | |
my \j = (1|2|3); | |
dd j.&ipry.HOW; | |
dd j.&ipry.^meta_method_table; | |
dd j.&ipry.^find_method('foo'); | |
.say for j.&ipry.eigenstates; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment