Created
September 15, 2015 14:16
-
-
Save jnthn/b291be5a7a18398849d4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
multi trait_mod:<is>(Attribute:D $attr, :$chainymutable!) { | |
$attr does role { | |
method compose(Mu \package) { | |
my constant NO_ARG = Mu.new; | |
my $this_attr = self; | |
package.^add_method: | |
$this_attr.name.substr(2), # strip sigil | |
method (Mu \value = NO_ARG) { | |
if value =:= NO_ARG { | |
$this_attr.get_value(self) | |
} | |
else { | |
$this_attr.set_value(self, value); | |
self | |
} | |
} | |
nextsame(); | |
} | |
} | |
} | |
class Point { | |
has $.x is chainymutable; | |
has $.y is chainymutable; | |
} | |
my $p = Point.new.x(42).y(69); | |
say $p.x; | |
say $p.y; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment