Skip to content

Commit 4bf022b

Browse files
committed
Dedups is required, refs #2745
1 parent c4bc016 commit 4bf022b

File tree

1 file changed

+28
-44
lines changed

1 file changed

+28
-44
lines changed

doc/Type/Attribute.pod6

Lines changed: 28 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ argument of C<is default> will set the default item value or hash value.
5353
5454
=head2 X<Trait is required|trait,is required (Attribute)>
5555
56+
Defined as:
57+
58+
multi sub trait_mod:<is> (Attribute $attr, :$required!)
59+
5660
The trait C<is required> will mark the attribute as to be filled with a value
5761
when the object is instantiated. Failing to do so will result in a runtime
5862
error.
@@ -76,6 +80,10 @@ CATCH{ default { say .^name, ': ', .Str } }
7680
# OUTPUT: «X::Attribute::Required: The attribute '$!a' is required because it is a good idea,␤but you did not provide a value for it.␤»
7781
=end code
7882
83+
C<is required> doesn't just affect the default constructor, it checks for the
84+
attribute at a lower level, so it will work for custom constructors written
85+
using L<bless|/routine/bless>.
86+
7987
=head2 X<trait is DEPRECATED|trait,is DEPRECATED (Attribute)>
8088
8189
multi sub trait_mod:<is>(Attribute:D $r, :$DEPRECATED!)
@@ -97,6 +105,26 @@ STDERR:
97105
# script.p6, line 5
98106
# Please use 'bar' instead.
99107
108+
=head2 X<trait is rw|trait,is rw (Attribute)>
109+
110+
Defined as:
111+
112+
multi sub trait_mod:<is> (Attribute:D $attr, :$rw!)
113+
114+
Marks an attribute as read/write as opposed to the default C<readonly>. The
115+
default accessor for the attribute will return a writable value.
116+
117+
class Boo {
118+
has $.bar is rw;
119+
has $.baz;
120+
};
121+
122+
my $boo = Boo.new;
123+
$boo.bar = 42; # works
124+
$boo.baz = 42;
125+
CATCH { default { put .^name, ': ', .Str } };
126+
# OUTPUT: «X::Assignment::RO: Cannot modify an immutable Any␤»
127+
100128
=head1 Methods
101129
102130
=head2 method name
@@ -220,50 +248,6 @@ Binds the value C<new_val> to this attribute of object C<$obj>.
220248
Note that this method violates encapsulation of the object, and should be
221249
used with care. Here be dragons.
222250
223-
=head1 Traits
224-
225-
=head2 trait is required
226-
227-
multi sub trait_mod:<is> (Attribute $attr, :$required!)
228-
229-
Marks an attribute as being required. If a value is not provided
230-
during object construction, an exception is thrown.
231-
232-
class Foo {
233-
has $.bar is required;
234-
has $.baz;
235-
};
236-
237-
Foo.new(bar => 42); # works
238-
Foo.new(baz => 42);
239-
CATCH { default { put .^name, ': ', .Str } };
240-
# OUTPUT: «X::Attribute::Required: The attribute '$!bar' is required, but you did not provide a value for it.␤»
241-
242-
C<is required> doesn't just affect the default constructor, it checks for the
243-
attribute at a lower level, so it will work for custom constructors written
244-
using L<bless|/routine/bless>.
245-
246-
247-
=head2 trait is rw
248-
249-
Defined as:
250-
251-
multi sub trait_mod:<is> (Attribute:D $attr, :$rw!)
252-
253-
Marks an attribute as read/write as opposed to the default C<readonly>. The
254-
default accessor for the attribute will return a writable value.
255-
256-
class Boo {
257-
has $.bar is rw;
258-
has $.baz;
259-
};
260-
261-
my $boo = Boo.new;
262-
$boo.bar = 42; # works
263-
$boo.baz = 42;
264-
CATCH { default { put .^name, ': ', .Str } };
265-
# OUTPUT: «X::Assignment::RO: Cannot modify an immutable Any␤»
266-
267251
=head2 method gist
268252
269253
Defined as

0 commit comments

Comments
 (0)