Roles

Learn about roles in Perl.

A role is a named collection of behavior and state. Whereas a class organizes behaviors and state into a template for objects, a role organizes a named collection of behaviors and state. We can instantiate a class but not a role. A role is something a class does.

Defining a role

Given an Animal that has an age and a Cheese that can age, one difference may be that Animal does the LivingBeing role, while Cheese does the Storable role:

Get hands-on with 1200+ tech skills courses.