Forked from anonymous/gist:6e0a148a351667b5d345
Last active
October 27, 2015 22:25
-
-
Save peschwa/9e071976dab9eb63fd42 to your computer and use it in GitHub Desktop.
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
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