Skip to content

Instantly share code, notes, and snippets.

@peschwa
Forked from anonymous/gist:6e0a148a351667b5d345
Last active October 27, 2015 22:25
Show Gist options
  • Save peschwa/9e071976dab9eb63fd42 to your computer and use it in GitHub Desktop.
Save peschwa/9e071976dab9eb63fd42 to your computer and use it in GitHub Desktop.
use v6;
role WriteOnce {
method compose($pkg) {
callsame;
$pkg.^find_method(self.name.substr(2)).wrap(-> $obj {
die "Cannot assign more than once to a writeonce attribute"
if self.get_value($obj).defined;
callsame;
});
}
}
multi sub trait_mod:<is>(Attribute:D $attr, :$w1!) {
$attr does WriteOnce;
$attr.set_rw();
warn "useless use of 'is w1' on $attr.name()" unless $attr.has_accessor;
}
class A { has $.foo is w1 }
my A $a .= new;
say $a.foo = 123; # OK
say $a.foo;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment