Skip to content

Commit e90e09d

Browse files
committed
[containers] explain how "is rw" attribute accessors work
1 parent b8c5ac4 commit e90e09d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/containers.pod

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,28 @@ Inside the subroutine, the lexpad entry for C<$a> points to the same
5555
container that C<$x> points to outside the subroutine. Which is why assignment
5656
to C<$a> also modifies the contents of C<$x>.
5757
58+
Likewise a routine can return a container if it is marked as C<is rw>:
59+
60+
my $x = 23;
61+
sub f() is rw { $x };
62+
f() = 42;
63+
say $x; # 42
64+
65+
For explicit returns, C<return-rw> instead of C<return> must be used.
66+
67+
Returning a container is how C<is rw> attribute accessors work. So
68+
69+
class A {
70+
has $.attr is rw;
71+
}
72+
73+
is equivalent to
74+
75+
class A {
76+
has $!attr;
77+
method attr() is rw { $!attr }
78+
}
79+
5880
=head2 Binding
5981
6082
Next to assignment, Perl 6 also supports I<binding> with the C<:=> operator.

0 commit comments

Comments
 (0)