Moose and Perl OO

Learn about features provided by Moose.

The Moose module

Moose provides many features beyond Perl’s default OO system. Although we can build everything we get with Moose either by ourselves The bless built-in associates the name of a class with a reference. That reference is now a valid invocant. Perl will perform method dispatch on it.or by cobbling it together with a series of CPAN distributions, Moose is worth using. It’s a coherent whole, with documentation, a mature and attentive development community, and a history of successful use in important projects.

Moose provides constructors, destructors, accessors, and encapsulation. We must do the work of declaring what we want, but we get safe and useful code in return. Moose objects can extend and work with objects from the vanilla Perl system.

While Moose is not a part of the Perl core, its popularity ensures that it’s available on many OS distributions. Perl distributions such as Strawberry Perl and ActivePerl also include it. Even though Moose is a CPAN module and not a core library, its cleanliness and simplicity make it essential to modern Perl programming.

Metaprogramming

Moose also allows metaprogramming—manipulating our objects through Moose itself. If you've ever wondered which methods are available on a class or an object or which attributes an object supports, this information is available:

Get hands-on with 1200+ tech skills courses.