Skip to content

Instantly share code, notes, and snippets.

@dwarring
Last active October 31, 2015 18:34
Show Gist options
  • Save dwarring/8e11f55207990944c0c9 to your computer and use it in GitHub Desktop.
Save dwarring/8e11f55207990944c0c9 to your computer and use it in GitHub Desktop.
Perl6 Proxys getting hammered
class C {
has $!foo;
method foo is rw {
say "foo";
$!foo;
}
has $!bar;
method bar is rw {
Proxy.new(
say "proxy new";
FETCH => sub ($) {
say "bar fetch";
$!bar
},
STORE => sub ($, $v) {
say "bar store";
$!bar = $v;
},
);
}
}
my $c = C.new;
say "FETCHES";
$c.foo;
$c.bar;
say "STORES";
$c.foo++;
$c.bar++;
OUTPUT:
FETCHES
foo
proxy new
bar fetch
bar fetch
bar fetch
STORES
foo
proxy new
bar fetch
bar fetch
bar fetch
bar fetch
bar fetch
bar fetch
bar fetch
bar store
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment