Moose::Manual(3)

✨ Moose::Manual β€” the whole vibe ✨

okay bestie, sit down, grab a boba πŸ§‹ because we're about to talk about Moose::Manual, which lives in the User Contributed Perl Documentation corner of the man pages. This is the front door to the whole Moose manual, and it's gonna tell you what Moose even is and why you should care. πŸ’–

🌸 VERSION 🌸

version 2.4000 β€” yes, that's the version, no I'm not being cute about it, that's literally the number. πŸ‘‘


πŸ’… WHAT IS MOOSE? πŸ’…

Moose is a complete object system for Perl 5. Think about any modern object-oriented language (and like, Perl 5 is definitely not one of those, no shade). Those languages give you keywords for declaring attributes, constructing objects, inheritance, and maybe even more. Those keywords are part of the language, and you never have to think about how they're actually implemented. Slay.

Moose wants to do that exact same thing for Perl 5 OO. We can't actually create new keywords (rude, I know), but we do hand you "sugar" that looks a whole lot like them. And more importantly: with Moose you define your class declaratively, without needing to know anything about blessed hashrefs, accessor methods, and all that jazz. ✨

With Moose you get to focus on the logical structure of your classes β€” the "what" instead of the "how". A class definition written with Moose reads like a list of very concise English sentences. It's giving poetry, honestly.

Moose is built on top of Class::MOP, a meta-object protocol (aka MOP). Using the MOP, Moose provides complete introspection for all Moose-using classes. Which means you can ask classes about their attributes, parents, children, methods, etc., all through a well-defined API. The MOP abstracts away the symbol table, looking at @ISA vars, and all the other crufty Perl tricks we know and love(?). 🫢

Moose is based in large part on the Perl 6 object system, and it also draws on the best ideas from CLOS, Smalltalk, and many other languages. Iconic behavior.


🌈 WHY MOOSE? 🌈

Moose makes Perl 5 OO both simpler and more powerful. It encapsulates Perl 5 power tools in high-level declarative APIs that are easy to use. And best of all? You don't need to be a wizard to use it. πŸ§™β™€οΈ

But if you do want to dig around in the guts, Moose lets you do that too β€” by using and extending its powerful introspection API. Main character energy either way.


πŸ¦‹ AN EXAMPLE πŸ¦‹

package Person;

use Moose;

has 'first_name' => (
    is  => 'rw',
    isa => 'Str',
);

has 'last_name' => (
    is  => 'rw',
    isa => 'Str',
);

no Moose;
__PACKAGE__->meta->make_immutable;

This is a complete and usable class definition! No cap, that's the whole thing. 😭

package User;

use DateTime;
use Moose;

extends 'Person';

has 'password' => (
    is  => 'rw',
    isa => 'Str',
);

has 'last_login' => (
    is      => 'rw',
    isa     => 'DateTime',
    handles => { 'date_of_last_login' => 'date' },
);

sub login {
    my $self = shift;
    my $pw   = shift;

    return 0 if $pw ne $self->password;

    $self->last_login( DateTime->now() );

    return 1;
}

no Moose;
__PACKAGE__->meta->make_immutable;

And when you're ready to instantiate your class in an application, you just use it in the "traditional" Perl manner:

use User;

my $user = User->new(
  first_name => 'Example',
  last_name  => 'User',
  password   => 'letmein',
);

$user->login('letmein');

say $user->date_of_last_login;

We're gonna leave the line-by-line explanation of all this to other documentation, but like β€” can you see how Moose reduces common OO idioms to simple declarative constructs? Obsessed. πŸ’–


πŸŽ€ TABLE OF CONTENTS πŸŽ€

This manual consists of a number of documents. A whole little family.

  • Moose::Manual::Concepts β€” Introduces Moose concepts, and contrasts them against "old school" Perl 5 OO.
  • Moose::Manual::Unsweetened β€” Shows two example classes, each written first with Moose and then with "plain old Perl 5".
  • Moose::Manual::Classes β€” How do you make use of Moose in your classes? Now that I'm a Moose, how do I subclass something?
  • Moose::Manual::Attributes β€” Attributes are a core part of the Moose OO system. An attribute is a piece of data that an object has. Moose has a lot of attribute-related features! πŸ”₯
  • Moose::Manual::Delegation β€” Delegation is a powerful way to make use of attributes which are themselves objects.
  • Moose::Manual::Construction β€” Learn how objects are built in Moose, and in particular about the BUILD and BUILDARGS methods. Also covers object destruction with DEMOLISH.
  • Moose::Manual::MethodModifiers β€” A method modifier lets you say "before calling method X, do this first", or "wrap method X in this code". Method modifiers are particularly handy in roles and with attribute accessors.
  • Moose::Manual::Roles β€” A role is something a class does (like Debuggable or Printable). Roles provide a way of adding behavior to classes that is orthogonal to inheritance.
  • Moose::Manual::Types β€” Moose's type system lets you strictly define what values an attribute can contain.
  • Moose::Manual::MOP β€” Moose's meta API system lets you ask classes about their parents, children, methods, attributes, etc.
  • Moose::Manual::MooseX β€” This document describes a few of the most useful Moose extensions on CPAN.
  • Moose::Manual::BestPractices β€” Moose has a lot of features, and there's definitely more than one way to do it. However, we think that picking a subset of these features and using them consistently makes everyone's life easier.
  • Moose::Manual::FAQ β€” Frequently asked questions about Moose.
  • Moose::Manual::Resources β€” Links to various tutorials, videos, blogs, presentations, interviews, etc...
  • Moose::Manual::Contributing β€” Interested in hacking on Moose? Read this. πŸ‘€
  • Moose::Manual::Delta β€” This document details backwards-incompatibilities and other major changes to Moose.

⭐ JUSTIFICATION ⭐

If you're still asking yourself "Why do I need this?", then this section is for you, bestie.

Another object system!?!?

Yes, we know there are many, many ways to build objects in Perl 5, many of them based on inside-out objects and other such things. Moose is different because it is not a new object system for Perl 5 β€” instead it's an extension of the existing object system.

Moose is built on top of Class::MOP, which is a metaclass system for Perl 5. This means that Moose not only makes building normal Perl 5 objects better, but it also provides the power of metaclass programming. ✨

Is this for real? Or is this just an experiment?

Moose is based on the prototypes and experiments Stevan did for the Perl 6 meta-model. However, Moose is NOT an experiment or prototype; it is for real. πŸ’―

Is this ready for use in production?

Yes.

Moose has been used successfully in production environments by many people and companies. There are Moose applications which have been in production with little or no issue now for years. We consider it highly stable and we are committed to keeping it stable. 🫢

Of course, in the end, you need to make this call yourself. If you have any questions or concerns, please feel free to email Stevan or the moose@perl.org list, or just stop by irc.perl.org#moose and ask away.

Is Moose just Perl 6 in Perl 5?

No. While Moose is very much inspired by Perl 6, it is not itself Perl 6. Instead, it is an OO system for Perl 5. Stevan built Moose because he was tired of writing the same old boring Perl 5 OO code, and drooling over Perl 6 OO. So instead of switching to Ruby, he wrote Moose :) πŸ’€

Wait, post modern, I thought it was just modern?

Stevan read Larry Wall's talk from the 1999 Linux World entitled "Perl, the first postmodern computer language" in which he talks about how he picked the features for Perl because he thought they were cool and he threw out the ones that he thought sucked. This got him thinking about how we have done the same thing in Moose. For Moose, we have "borrowed" features from Perl 6, CLOS (LISP), Smalltalk, Java, BETA, OCaml, Ruby and more, and the bits we didn't like (cause they sucked) we tossed aside. So for this reason (and a few others) Stevan has re-dubbed Moose a postmodern object system.

Nuff Said. πŸ’…


πŸ‘‘ AUTHORS πŸ‘‘

  • Stevan Little <stevan@cpan.org>
  • Dave Rolsky <autarch@urth.org>
  • Jesse Luehrs <doy@cpan.org>
  • Shawn M Moore <sartak@cpan.org>
  • Χ™Χ•Χ‘Χœ Χ§Χ•Χ’'מן (Yuval Kogman) <nothingmuch@woobling.org>
  • Karen Etheridge <ether@cpan.org>
  • Florian Ragwitz <rafl@debian.org>
  • Hans Dieter Pearcey <hdp@cpan.org>
  • Chris Prather <chris@prather.org>
  • Matt S Trout <mstrout@cpan.org>

This software is copyright (c) 2006 by Infinity Interactive, Inc.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


okay that's the whole page, you ate it, go forth and write some classes πŸŽ€πŸ¦‹βœ¨

And for the lil sign-off β€” this is Moose::Manual(3), generated by perl v5.42.0 on 2025-07-25. Screenshot it, frame it, it's iconic. πŸ«ΆπŸ’–

πŸ“¦ where this page comes from