Roles - an alternate form of class inheritance

Roles are collections of methods and attributes that can be mixed into classes. A role provides an alternate form of code reuse from inheritance. Roles are typically mixed in using "does".

role Seller {
  method sell { say self.^name ~ ' is selling' }

role Buyer {
  method buy { say self.^name ~ ' is buying' }

class Consumer does Buyer {}
class Producer does Seller {}
class Company does Buyer does Seller {}

my $producer =;
my $consumer =;
my $company =;



Producer is selling
Consumer is buying
Company is selling
Company is buying

raku (17)