trait is rw
| 1 | language documentation Type system | 
| 1.1 | (Type system) trait is rw | 
| 2 | class Routine | 
| 2.1 | (Routine) trait is rw | 
Documentation for trait is rw assembled from the following types:
language documentation Type system
From Type system
(Type system) trait is rw
Defined as:
sub trait_mod:<is>(Mu , :!)
The trait 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»
class Routine
From Routine
(Routine) trait is rw
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;
produces
("some" => ).hash
Note that return marks return values as read only; if you need an early exit from an is rw routine, you have to use return-rw instead.