Skip to content

Instantly share code, notes, and snippets.

@lizmat
Last active September 26, 2019 12:30
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 lizmat/90974d3d89f7f64d02122362ff39c6cc to your computer and use it in GitHub Desktop.
Save lizmat/90974d3d89f7f64d02122362ff39c6cc to your computer and use it in GitHub Desktop.
alternate Proxy implementation
class Proxy {
has Mu &.FETCH;
has Mu &.STORE;
my constant $FETCH = method FETCH(\SELF:) {
my $self := nqp::create(Scalar);
nqp::bindattr($self, Scalar, '$!value', SELF);
nqp::decont(&!FETCH($self))
}
my constant $STORE = method STORE(\SELF: \value) {
my $self := nqp::create(Scalar);
nqp::bindattr($self, Scalar, '$!value', SELF);
&!STORE($self, value)
}
BEGIN {
Proxy.HOW.set_container_spec(Proxy, nqp::hash(
'fetch', nqp::getstaticcode(nqp::getattr($FETCH,Code,'$!do')),
'store', nqp::getstaticcode(nqp::getattr($STORE,Code,'$!do'))
));
Proxy.HOW.compose_repr(Proxy);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment