Skip to content

Commit 205c12e

Browse files
authored
Merge pull request #3250 from uzluisf/master
Partially document the 'is built' trait
2 parents 6612a01 + a9ab679 commit 205c12e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

doc/Type/Attribute.pod6

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,29 @@ default accessor for the attribute will return a writable value.
111111
CATCH { default { put .^name, ': ', .Str } };
112112
# OUTPUT: «X::Assignment::RO: Cannot modify an immutable Any␤»
113113
114+
=head2 X<trait is built|trait,is built (Attribute)>
115+
116+
Defined as:
117+
118+
multi sub trait_mod:<is>(Attribute:D $a, :$built!)
119+
120+
By default, this trait allows setting up a I«private attribute» during object
121+
construction via C«.new». The same trait can be used to prevent setting up a
122+
I«public attribute» via C«.new» by passing it the boolean value C«False».
123+
124+
class Foo {
125+
has $!bar is built; # same as `is built(True)`
126+
has $.baz is built(False);
127+
128+
method bar {
129+
$!bar
130+
}
131+
}
132+
133+
my $foo = Foo.new(bar => 1, baz => 2);
134+
say $foo.bar; # «1␤»
135+
say $foo.baz; # «Any␤»
136+
114137
=head1 Methods
115138
116139
The usual way to obtain an object of type C<Attribute> is by introspection:

0 commit comments

Comments
 (0)