Skip to content

Commit 13b933b

Browse files
authored
In Attribute.rakudoc, create section for trait is readonly (#4692)
* create section for trait is readonly * correct signature of trait readonly Make the signature match exactly the (only) one obtained via introspection, e.g. via: &trait_mod:<is>.candidates».signature».raku.grep(/readonly/).say; * skip CI test for error-illustrating code * skip CI test for signature listing * remove erroneous $ compare output of introspection `&trait_mod:<is>.candidates».signature».raku.grep(/ \(\$\) /)».say` * remove erroneous `my $` * remove `=for code` * correct comma to period
1 parent fa0b7f8 commit 13b933b

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

doc/Type/Attribute.rakudoc

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ BEGIN {
4949

5050
=head1 Traits
5151

52-
=head2 X<Trait is default|Traits,is default>
52+
=head2 X<trait is default|Traits,is default>
5353

5454
An attribute that is assigned L<C<Nil>|/type/Nil> will revert to its default value
5555
set with the trait C<is default>. In the case of arrays or associatives, the
@@ -70,7 +70,7 @@ argument of C<is default> will set the default item value or hash value.
7070
$foo.bar =Nil;
7171
say $foo; # OUTPUT: «Foo.new(bar => [42])␤»
7272

73-
=head2 X<Trait is required|Traits,is required>
73+
=head2 X<trait is required|Traits,is required>
7474

7575
multi trait_mod:<is> (Attribute $attr, :$required!)
7676

@@ -151,6 +151,27 @@ default accessor for the attribute will return a writable value.
151151
CATCH { default { put .^name, ': ', .Str } };
152152
# OUTPUT: «X::Assignment::RO: Cannot modify an immutable Any␤»
153153

154+
=head2 X<trait is readonly|Traits,is readonly>
155+
156+
multi trait_mod:<is> (Attribute:D $attr, :readonly($)!)
157+
158+
Marks as C<readonly> an attribute of a class that has the C<is rw> trait.
159+
160+
=begin code :skip-test<illustrates error>
161+
class Thing is rw {
162+
has $.form;
163+
has $.matter is readonly;
164+
};
165+
166+
my $t = Thing.new(matter => "copper", form => "cubic");
167+
$t.form = "round"; # OK, form is rw
168+
$t.matter = "iron"; # not OK, matter is readonly
169+
# OUTPUT: «Cannot modify an immutable Str (copper)␤...»
170+
=end code
171+
172+
The attributes of classes without the C<is rw> trait are already readonly by default.
173+
Thus, in classes without the C<is rw> trait, the attribute trait C<is readonly> is redundant.
174+
154175
=head2 X<trait is built|Traits,is built>
155176

156177
multi trait_mod:<is>(Attribute:D $a, :$built!)

0 commit comments

Comments
 (0)