Class Attributes
Learn about the private data associated with the objects.
Every Perl object is unique. Objects can contain private data associated with each unique object, often called attributes, instance data, or object state.
Defining an attribute
We define an attribute by declaring it as part of the class:
Press + to interact
package Cat {use Moose;has 'name', is => 'ro', isa => 'Str';}
Moose exports the has()
function for us to use to declare an attribute. In English, this code reads as, “Cat
objects have a name
attribute. It’s read-only, and it’s a string.” The first argument, name
, is the attribute’s name. The is => 'ro'
pair of arguments declares that this ...