Skip to content

Instantly share code, notes, and snippets.

@lizmat
Created September 12, 2015 08:51
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/bb02b2ca33be658a77d1 to your computer and use it in GitHub Desktop.
Save lizmat/bb02b2ca33be658a77d1 to your computer and use it in GitHub Desktop.
example of a simple "is tracked" trait in development
class Foo {
has $.a;
has $.b;
has $.c;
has $.changed = False;
method a { self!proxy($!a) }
method b { self!proxy($!b) }
method c { self!proxy($!c) }
method !proxy(\attr) {
Proxy.new(
FETCH => -> { attr },
STORE => -> $, $value { $!changed = True; attr = $value }
);
}
}
my $f = Foo.new( a => 42, b => 666 );
say $f.changed;
$f.a = 67;
say $f.changed;
$f.perl.say;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment