Skip to content

Commit

Permalink
Partially document the 'is built' trait
Browse files Browse the repository at this point in the history
  • Loading branch information
uzluisf committed Feb 25, 2020
1 parent 2e51f74 commit a9ab679
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions doc/Type/Attribute.pod6
Expand Up @@ -111,6 +111,29 @@ default accessor for the attribute will return a writable value.
CATCH { default { put .^name, ': ', .Str } };
# OUTPUT: «X::Assignment::RO: Cannot modify an immutable Any␤»
=head2 X<trait is built|trait,is built (Attribute)>
Defined as:
multi sub trait_mod:<is>(Attribute:D $a, :$built!)
By default, this trait allows setting up a I«private attribute» during object
construction via C«.new». The same trait can be used to prevent setting up a
I«public attribute» via C«.new» by passing it the boolean value C«False».
class Foo {
has $!bar is built; # same as `is built(True)`
has $.baz is built(False);
method bar {
$!bar
}
}
my $foo = Foo.new(bar => 1, baz => 2);
say $foo.bar; # «1␤»
say $foo.baz; # «Any␤»
=head1 Methods
The usual way to obtain an object of type C<Attribute> is by introspection:
Expand Down

0 comments on commit a9ab679

Please sign in to comment.