Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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