Last active
October 31, 2015 18:34
-
-
Save dwarring/8e11f55207990944c0c9 to your computer and use it in GitHub Desktop.
Perl6 Proxys getting hammered
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 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