Skip to content

Instantly share code, notes, and snippets.

@gfldex
Last active February 10, 2021 23:23
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/31f7bd6a393ee3ef20db96ce1d5468f3 to your computer and use it in GitHub Desktop.
Save gfldex/31f7bd6a393ee3ef20db96ce1d5468f3 to your computer and use it in GitHub Desktop.
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