trait is rw
Documentation for trait
is rw assembled from the following types:
sub trait_mod:<is>(Mu , :!)
is rw on a class will create writable accessor methods on all public attributes of that class.
is rw;my = C.new.a = 42;say ; # OUTPUT: «42␤»
multi sub trait_mod:<is> (Attribute , :!)
Marks an attribute as read/write as opposed to the default
readonly. The default accessor for the attribute will return a writable value.
;my = Boo.new;.bar = 42; # works.baz = 42;CATCH ;# OUTPUT: «X::Assignment::RO: Cannot modify an immutable Any␤»
multi sub trait_mod:<is>(Routine , :!)
When a routine is modified with this trait, its return value will be writable. This is useful when returning variables or writable elements of hashes or arrays, for example:
sub walk(\thing, *) is rwmy ;walk(, 'some', 'key', 1, 2) = 'autovivified';say .perl;
("some" => ).hash
return marks return values as read only; if you need an early exit from an
is rw routine, you have to use