September 2017
Beginner
402 pages
9h 52m
English
In the previous section, we created a pair of getter and setter methods, get_rooms and set_rooms, for only one of the attributes of the House class. We can also do that for other attributes, such as $!area and $!height, but that requires a lot of copy-and-paste work and is not the best way to spend your time.
Actually, the dot syntax that we were using earlier in this chapter to set and read attributes is a syntactic cheat to use the getter and setter methods that Perl 6 created for us. Let us examine it step by step.
First, create a simple class with a $. attribute:
class X { has $.y;}my $x = X.new(y => 1);say $x.y; # 1
The $x object has an attribute named y. This is a public attribute (because of the . twigil) ...
Read now
Unlock full access