e13ec0edaa14652bc24dbb1c3a5c3dde3655821f
[gitmo/Moose.git] / lib / Moose / Cookbook.pod
1 package Moose::Cookbook;
2
3 # ABSTRACT: How to cook a Moose
4
5 __END__
6
7
8 =pod
9
10 =head1 DESCRIPTION
11
12 The Moose cookbook is a series of recipes showing various Moose
13 features. Most recipes present some code demonstrating some feature,
14 and then explain the details of the code.
15
16 You should probably read the L<Moose::Manual> first. The manual
17 explains Moose concepts without being too code-heavy.
18
19 =head1 RECIPES
20
21 =head2 Basic Moose
22
23 These recipes will give you a good overview of Moose's capabilities, starting
24 with simple attribute declaration, and moving on to more powerful features like
25 laziness, types, type coercion, method modifiers, and more.
26
27 =over 4
28
29 =item L<Moose::Cookbook::Basics::Point_AttributesAndSubclassing>
30
31 A simple Moose-based class. Demonstrates basic Moose attributes and subclassing.
32
33 =item L<Moose::Cookbook::Basics::BankAccount_MethodModifiersAndSubclassing>
34
35 A slightly more complex Moose class. Demonstrates using a method modifier in a
36 subclass.
37
38 =item L<Moose::Cookbook::Basics::BinaryTree_AttributeFeatures>
39
40 Demonstrates several attribute features, including types, weak
41 references, predicates ("does this object have a foo?"), defaults,
42 laziness, and triggers.
43
44 =item L<Moose::Cookbook::Basics::Company_Subtypes>
45
46 Introduces the creation and use of custom types, a C<BUILD> method, and the
47 use of C<override> in a subclass. This recipe also shows how to model a set of
48 classes that could be used to model companies, people, employees, etc.
49
50 =item L<Moose::Cookbook::Basics::HTTP_SubtypesAndCoercion>
51
52 This recipe covers more subtype creation, including the use of type coercions.
53
54 =item L<Moose::Cookbook::Basics::Immutable>
55
56 Making a class immutable greatly increases the speed of accessors and
57 object construction.
58
59 =item L<Moose::Cookbook::Basics::BinaryTree_BuilderAndLazyBuild> - Builder methods and lazy_build
60
61 The builder feature provides an inheritable and role-composable way to
62 provide a default attribute value.
63
64 =item L<Moose::Cookbook::Basics::Genome_OverloadingSubtypesAndCoercion>
65
66 Demonstrates using operator overloading, coercion, and subtypes to
67 model how eye color is determined during reproduction.
68
69 =item L<Moose::Cookbook::Basics::Person_BUILDARGSAndBUILD>
70
71 This recipe demonstrates the use of C<BUILDARGS> and C<BUILD> to hook
72 into object construction.
73
74 =item L<Moose::Cookbook::Basics::DateTime_ExtendingNonMooseParent>
75
76 In this recipe, we make a Moose-based subclass of L<DateTime>, a
77 module which does not use Moose itself.
78
79 =item L<Moose::Cookbook::Basics::Document_AugmentAndInner>
80
81 Demonstrates the use of C<augment> method modifiers, a way of turning
82 the usual method overriding style "inside-out".
83
84 =back
85
86 =head2 Moose Roles
87
88 These recipes will show you how to use Moose roles.
89
90 =over 4
91
92 =item L<Moose::Cookbook::Roles::Comparable_CodeReuse>
93
94 Demonstrates roles, which are also sometimes known as traits or
95 mix-ins. Roles provide a method of code re-use which is orthogonal to
96 subclassing.
97
98 =item L<Moose::Cookbook::Roles::Restartable_AdvancedComposition>
99
100 Sometimes you just want to include part of a role in your
101 class. Sometimes you want the whole role but one of its methods
102 conflicts with one in your class. With method exclusion and aliasing,
103 you can work around these problems.
104
105 =item L<Moose::Cookbook::Roles::ApplicationToInstance>
106
107 In this recipe, we apply a role to an existing object instance.
108
109 =back
110
111 =head2 Meta Moose
112
113 These recipes show you how to write your own meta classes, which lets
114 you extend the object system provided by Moose.
115
116 =over 4
117
118 =item L<Moose::Cookbook::Meta::WhyMeta>
119
120 If you're wondering what all this "meta" stuff is, and why you should
121 care about it, read this "recipe".
122
123 =item L<Moose::Cookbook::Meta::Labeled_AttributeTrait>
124
125 Extending Moose's attribute metaclass is a great way to add
126 functionality. However, attributes can only have one metaclass.
127 Applying roles to the attribute metaclass lets you provide
128 composable attribute functionality.
129
130 =item L<Moose::Cookbook::Meta::Table_MetaclassTrait>
131
132 This recipe takes the class metaclass we saw in the previous recipe
133 and reimplements it as a metaclass trait.
134
135 =item L<Moose::Cookbook::Meta::PrivateOrPublic_MethodMetaclass>
136
137 This recipe shows a custom method metaclass that implements making a
138 method private.
139
140 =item L<Moose::Cookbook::Meta::GlobRef_InstanceMetaclass>
141
142 This recipe shows an example of how you create your own meta-instance
143 class. The meta-instance determines the internal structure of object
144 instances and provide access to attribute slots.
145
146 In this particular instance, we use a blessed glob reference as the instance
147 instead of a blessed hash reference.
148
149 =item Hooking into immutabilization (TODO)
150
151 Moose has a feature known as "immutabilization". By calling C<<
152 __PACKAGE__->meta()->make_immutable() >> after defining your class
153 (attributes, roles, etc), you tell Moose to optimize things like
154 object creation, attribute access, and so on.
155
156 If you are creating your own metaclasses, you may need to hook into
157 the immutabilization system. This cuts across a number of spots,
158 including the metaclass class, meta method classes, and possibly the
159 meta-instance class as well.
160
161 This recipe shows you how to write extensions which immutabilize
162 properly.
163
164 =back
165
166 =head2 Extending Moose
167
168 These recipes cover some more ways to extend Moose, and will be useful
169 if you plan to write your own C<MooseX> module.
170
171 =over 4
172
173 =item L<Moose::Cookbook::Extending::ExtensionOverview>
174
175 There are quite a few ways to extend Moose. This recipe provides an
176 overview of each method, and provides recommendations for when each is
177 appropriate.
178
179 =item L<Moose::Cookbook::Extending::Debugging_BaseClassRole>
180
181 Many base object class extensions can be implemented as roles. This
182 example shows how to provide a base object class debugging role that
183 is applied to any class that uses a notional C<MooseX::Debugging>
184 module.
185
186 =item L<Moose::Cookbook::Extending::Mooseish_MooseSugar>
187
188 This recipe shows how to provide a replacement for C<Moose.pm>. You
189 may want to do this as part of the API for a C<MooseX> module,
190 especially if you want to default to a new metaclass class or base
191 object class.
192
193 =back
194
195 =head1 SNACKS
196
197 =over 4
198
199 =item L<Moose::Cookbook::Snack::Keywords>
200
201 =item L<Moose::Cookbook::Snack::Types>
202
203 =back
204
205 =head1 SEE ALSO
206
207 =over 4
208
209 =item L<http://www.gsph.com/index.php?Lang=En&ID=291>
210
211 =back
212
213 =cut