September 2017
Beginner
402 pages
9h 52m
English
The does operator mixes a role into an object. We will talk about mix-ins in Chapter 8, Object-Oriented Programming. Anyway, consider a brief example:
class Animal {}role Barking { method bark() { say "Bow-wow!"; }}my $dog = Animal.new();$dog does Barking;$dog.bark();
Here, the $dog variable is first created as an instance of the Animal class. Then, the behavior of the Barking role is attached to it. After that, the $dog variable can bark().
Read now
Unlock full access