Lably
Skip to content

Moose (Perl)

  • 7 min read
  • 3 chapters

Related on Lably

Through Object (computer science), Object-oriented programming and Class (programming)

Features

Moose is built on Class::MOP, a metaobject protocol (MOP). Using the MOP, Moose provides complete type introspection for all Moose-using classes.

Classes

Moose allows a programmer to create classes:

  • A class has zero or more attributes.
  • A class has zero or more methods.
  • A class has zero or more superclasses (a.k.a. parent classes). A class inherits from its superclass(es). Moose supports multiple inheritance.
  • A class has zero or more method modifiers. These modifiers can apply to its own methods, methods that are inherited from its ancestors or methods that are provided by roles.
  • A class does zero or more roles (also known as traits in other programming languages).
  • A class has a constructor and a destructor.
  • A class has a metaclass.

Attributes

An attribute is a property of the class that defines it.

  • An attribute always has a name, and it may have a number of other defining characteristics.
  • An attribute's characteristics may include a read/write flag, a type, accessor method names, delegations, a default value and lazy initialization.

Roles

Roles in Moose are based on traits. They perform a similar task as mixins, but are composed horizontally rather than inherited. They are also somewhat like interfaces, but unlike some implementations of interfaces they can provide a default implementation. Roles can be applied to individual instances as well as Classes.

  • A role has zero or more attributes.
  • A role has zero or more methods.
  • A role has zero or more method modifiers.
  • A role has zero or more required methods.

Sign in to keep reading

2 more chapters are free with a Lably account.

More in Computing and communication