3 # ABSTRACT: What is Moose, and how do I use it?
11 Moose is a I<complete> object system for Perl 5. Consider any modern
12 object-oriented language (which Perl 5 definitely isn't). It provides
13 keywords for attribute declaration, object construction, inheritance,
14 and maybe more. These keywords are part of the language, and you don't
15 care how they are implemented.
17 Moose aims to do the same thing for Perl 5 OO. We can't actually
18 create new keywords, but we do offer "sugar" that looks a lot like
19 them. More importantly, with Moose, you I<define your class
20 declaratively>, without needing to know about blessed hashrefs,
21 accessor methods, and so on.
23 With Moose, you can concentrate on the I<logical> structure of your
24 classes, focusing on "what" rather than "how". A class definition with
25 Moose reads like a list of very concise English sentences.
27 Moose is built on top of C<Class::MOP>, a meta-object protocol (aka
28 MOP). Using the MOP, Moose provides complete introspection for all
29 Moose-using classes. This means you can ask classes about their
30 attributes, parents, children, methods, etc., all using a well-defined
31 API. The MOP abstracts away the symbol table, looking at C<@ISA> vars,
32 and all the other crufty Perl tricks we know and love(?).
34 Moose is based in large part on the Perl 6 object system, as well as
35 drawing on the best ideas from CLOS, Smalltalk, and many other
40 Moose makes Perl 5 OO both simpler and more powerful. It encapsulates
41 Perl 5 power tools in high-level declarative APIs which are easy to
42 use. Best of all, you don't need to be a wizard to use it.
44 But if you want to dig about in the guts, Moose lets you do that too,
45 by using and extending its powerful introspection API.
64 __PACKAGE__->meta->make_immutable;
66 This is a I<complete and usable> class definition!
83 handles => { 'date_of_last_login' => 'date' },
90 return 0 if $pw ne $self->password;
92 $self->last_login( DateTime->now() );
98 __PACKAGE__->meta->make_immutable;
100 We'll leave the line-by-line explanation of this code to other
101 documentation, but you can see how Moose reduces common OO idioms to
102 simple declarative constructs.
104 =head1 TABLE OF CONTENTS
106 This manual consists of a number of documents.
110 =item L<Moose::Manual::Concepts>
112 Introduces Moose concepts, and contrasts them against "old school"
115 =item L<Moose::Manual::Unsweetened>
117 Shows two example classes, each written first with Moose and then with
120 =item L<Moose::Manual::Classes>
122 How do you make use of Moose in your classes? Now that I'm a Moose,
123 how do I subclass something?
125 =item L<Moose::Manual::Attributes>
127 Attributes are a core part of the Moose OO system. An attribute is a
128 piece of data that an object has. Moose has a lot of attribute-related
131 =item L<Moose::Manual::Delegation>
133 Delegation is a powerful way to make use of attributes which are
136 =item L<Moose::Manual::Construction>
138 Learn how objects are built in Moose, and in particular about the
139 C<BUILD> and C<BUILDARGS> methods. Also covers object destruction
142 =item L<Moose::Manual::MethodModifiers>
144 A method modifier lets you say "before calling method X, do this
145 first", or "wrap method X in this code". Method modifiers are
146 particularly handy in roles and with attribute accessors.
148 =item L<Moose::Manual::Roles>
150 A role is something a class does (like "Debuggable" or
151 "Printable"). Roles provide a way of adding behavior to classes that
152 is orthogonal to inheritance.
154 =item L<Moose::Manual::Types>
156 Moose's type system lets you strictly define what values an attribute
159 =item L<Moose::Manual::MOP>
161 Moose's meta API system lets you ask classes about their parents,
162 children, methods, attributes, etc.
164 =item L<Moose::Manual::MooseX>
166 This document describes a few of the most useful Moose extensions on
169 =item L<Moose::Manual::BestPractices>
171 Moose has a lot of features, and there's definitely more than one way
172 to do it. However, we think that picking a subset of these features
173 and using them consistently makes everyone's life easier.
175 =item L<Moose::Manual::FAQ>
177 Frequently asked questions about Moose.
179 =item L<Moose::Manual::Contributing>
181 Interested in hacking on Moose? Read this.
183 =item L<Moose::Manual::Delta>
185 This document details backwards-incompatibilities and other major
192 If you're still asking yourself "Why do I need this?", then this
197 =item Another object system!?!?
199 Yes, we know there are many, many ways to build objects in Perl 5,
200 many of them based on inside-out objects and other such things. Moose
201 is different because it is not a new object system for Perl 5, but
202 instead an extension of the existing object system.
204 Moose is built on top of L<Class::MOP>, which is a metaclass system
205 for Perl 5. This means that Moose not only makes building normal
206 Perl 5 objects better, but it also provides the power of metaclass
209 =item Is this for real? Or is this just an experiment?
211 Moose is I<based> on the prototypes and experiments Stevan did for the
212 Perl 6 meta-model. However, Moose is B<NOT> an experiment or
213 prototype; it is for B<real>.
215 =item Is this ready for use in production?
219 Moose has been used successfully in production environments by many
220 people and companies. There are Moose applications which have been in
221 production with little or no issue now for years. We consider it
222 highly stable and we are committed to keeping it stable.
224 Of course, in the end, you need to make this call yourself. If you
225 have any questions or concerns, please feel free to email Stevan or
226 the moose@perl.org list, or just stop by irc.perl.org#moose and ask
229 =item Is Moose just Perl 6 in Perl 5?
231 No. While Moose is very much inspired by Perl 6, it is not itself Perl
232 6. Instead, it is an OO system for Perl 5. Stevan built Moose because
233 he was tired of writing the same old boring Perl 5 OO code, and
234 drooling over Perl 6 OO. So instead of switching to Ruby, he wrote
237 =item Wait, I<post> modern, I thought it was just I<modern>?
239 Stevan read Larry Wall's talk from the 1999 Linux World entitled
240 "Perl, the first postmodern computer language" in which he talks about
241 how he picked the features for Perl because he thought they were cool
242 and he threw out the ones that he thought sucked. This got him
243 thinking about how we have done the same thing in Moose. For Moose, we
244 have "borrowed" features from Perl 6, CLOS (LISP), Smalltalk, Java,
245 BETA, OCaml, Ruby and more, and the bits we didn't like (cause they
246 sucked) we tossed aside. So for this reason (and a few others) Stevan
247 has re-dubbed Moose a I<postmodern> object system.