In Attribute§
See primary documentation in context for trait is built.
multi trait_mod:<is>(Attribute:D $a, :$built!)
By default, this trait allows setting up a private attribute during object construction via .new. The same trait can be used to prevent setting up a public attribute via .new by passing it the Boolean value False. Setting up an attribute with its value is ordinarily handled by assigning the value, but if :bind is passed, then it will be bound instead:
class Foo { has $!bar is built; # same as `is built(True)` has $.baz is built(False); has $!qux is built(:bind); method bar(::?CLASS:D:) { $!bar } method qux(::?CLASS:D:) { $!qux } } my Foo:D $foo .= new: :bar[], :baz[], :qux[]; say $foo.bar.raku; # OUTPUT: «$[]» say $foo.baz.raku; # OUTPUT: «Any» say $foo.qux.raku; # OUTPUT: «[]»
The built trait also allows named arguments to be specified. Currently the :bind named argument can be specified. In that case, any (default) value will be bound to the attribute, rather than assigned. This allows for specifying a Proxy to an attribute:
class Foo { has $!foo is built(:bind) = Proxy.new: :STORE{...}, :FETCH{...} }
Available as of the 2020.01 release of the Rakudo compiler.