Commit | Line | Data |
daa0fd7d |
1 | package Moose::Cookbook; |
471c4f09 |
2 | |
daa0fd7d |
3 | # ABSTRACT: How to cook a Moose |
4 | |
5 | __END__ |
471c4f09 |
6 | |
471c4f09 |
7 | |
daa0fd7d |
8 | =pod |
471c4f09 |
9 | |
10 | =head1 DESCRIPTION |
11 | |
ad248e00 |
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. |
471c4f09 |
15 | |
ad248e00 |
16 | You should probably read the L<Moose::Manual> first. The manual |
17 | explains Moose concepts without being too code-heavy. |
734d1752 |
18 | |
471c4f09 |
19 | =head1 RECIPES |
20 | |
496b74ab |
21 | =head2 Basic Moose |
22 | |
1068dcb5 |
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. |
4eec354b |
26 | |
471c4f09 |
27 | =over 4 |
28 | |
c4fde3b5 |
29 | =item L<Moose::Cookbook::Basics::Point_AttributesAndSubclassing> |
471c4f09 |
30 | |
c4fde3b5 |
31 | A simple Moose-based class. Demonstrates basic Moose attributes and subclassing. |
cb2478d4 |
32 | |
7b0a6766 |
33 | =item L<Moose::Cookbook::Basics::BankAccount_MethodModifiersAndSubclassing> |
471c4f09 |
34 | |
7b0a6766 |
35 | A slightly more complex Moose class. Demonstrates using a method modifier in a |
36 | subclass. |
cb2478d4 |
37 | |
ed82277c |
38 | =item L<Moose::Cookbook::Basics::BinaryTree_AttributeFeatures> |
471c4f09 |
39 | |
f7f3648d |
40 | Demonstrates several attribute features, including types, weak |
0fde1850 |
41 | references, predicates ("does this object have a foo?"), defaults, |
42 | laziness, and triggers. |
cb2478d4 |
43 | |
2326164e |
44 | =item L<Moose::Cookbook::Basics::Company_Subtypes> |
471c4f09 |
45 | |
2326164e |
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. |
cb2478d4 |
49 | |
e5a728d9 |
50 | =item L<Moose::Cookbook::Basics::HTTP_SubtypesAndCoercion> |
471c4f09 |
51 | |
e5a728d9 |
52 | This recipe covers more subtype creation, including the use of type coercions. |
cb2478d4 |
53 | |
021b8139 |
54 | =item L<Moose::Cookbook::Basics::Recipe7> - Making Moose fast with immutable |
496b74ab |
55 | |
5de2944f |
56 | Making a class immutable greatly increases the speed of accessors and |
57 | object construction. |
cb2478d4 |
58 | |
1f476b5f |
59 | =item L<Moose::Cookbook::Basics::Recipe8> - Builder methods and lazy_build |
496b74ab |
60 | |
fbd7ad7a |
61 | The builder feature provides an inheritable and role-composable way to |
62 | provide a default attribute value. |
cb2478d4 |
63 | |
1f476b5f |
64 | =item L<Moose::Cookbook::Basics::Recipe9> - Operator overloading, subtypes, and coercion |
c2a0627f |
65 | |
48757542 |
66 | Demonstrates using operator overloading, coercion, and subtypes to |
a8b3fe62 |
67 | model how eye color is determined during reproduction. |
c2a0627f |
68 | |
1f476b5f |
69 | =item L<Moose::Cookbook::Basics::Recipe10> - Using BUILDARGS and BUILD to hook into object construction |
45ef8386 |
70 | |
04d80e2a |
71 | This recipe demonstrates the use of C<BUILDARGS> and C<BUILD> to hook |
72 | into object construction. |
45ef8386 |
73 | |
1f476b5f |
74 | =item L<Moose::Cookbook::Basics::Recipe11> - Extending a non-Moose base class |
5f9e373d |
75 | |
76 | In this recipe, we make a Moose-based subclass of L<DateTime>, a |
77 | module which does not use Moose itself. |
78 | |
174418c2 |
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 | |
496b74ab |
84 | =back |
85 | |
86 | =head2 Moose Roles |
87 | |
4eec354b |
88 | These recipes will show you how to use Moose roles. |
89 | |
496b74ab |
90 | =over 4 |
91 | |
13dbfe49 |
92 | =item L<Moose::Cookbook::Roles::Recipe1> - The Moose::Role example |
496b74ab |
93 | |
f7f3648d |
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. |
cb2478d4 |
97 | |
13dbfe49 |
98 | =item L<Moose::Cookbook::Roles::Recipe2> - Advanced Role Composition - method exclusion and aliasing |
496b74ab |
99 | |
2e3d0a0a |
100 | Sometimes you just want to include part of a role in your |
dab94063 |
101 | class. Sometimes you want the whole role but one of its methods |
2e3d0a0a |
102 | conflicts with one in your class. With method exclusion and aliasing, |
103 | you can work around these problems. |
cb2478d4 |
104 | |
9a823f26 |
105 | =item L<Moose::Cookbook::Roles::Recipe3> - Applying a role to an object instance |
104379bc |
106 | |
9a823f26 |
107 | In this recipe, we apply a role to an existing object instance. |
cb2478d4 |
108 | |
496b74ab |
109 | =back |
110 | |
111 | =head2 Meta Moose |
112 | |
4eec354b |
113 | These recipes show you how to write your own meta classes, which lets |
dab94063 |
114 | you extend the object system provided by Moose. |
4eec354b |
115 | |
496b74ab |
116 | =over 4 |
117 | |
17a65b17 |
118 | =item L<Moose::Cookbook::Meta::Recipe1> - Welcome to the meta-world (Why Go Meta?) |
496b74ab |
119 | |
38031ac8 |
120 | If you're wondering what all this "meta" stuff is, and why you should |
121 | care about it, read this "recipe". |
cb2478d4 |
122 | |
43aa5bf9 |
123 | =item L<Moose::Cookbook::Meta::Recipe3> - Labels implemented via attribute traits |
a7d0cd00 |
124 | |
aff0421c |
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. |
cb2478d4 |
129 | |
c5b9daec |
130 | =item L<Moose::Cookbook::Meta::Recipe5> - The "table" attribute implemented as a metaclass trait |
24a8fe99 |
131 | |
505dcac2 |
132 | This recipe takes the class metaclass we saw in the previous recipe |
c5b9daec |
133 | and reimplements it as a metaclass trait. |
cb2478d4 |
134 | |
505dcac2 |
135 | =item L<Moose::Cookbook::Meta::Recipe6> - A method metaclass for marking methods public or private |
136 | |
137 | This recipe shows a custom method metaclass that implements making a |
138 | method private. |
139 | |
140 | =item L<Moose::Cookbook::Meta::Recipe7> - Using a blessed array reference as an object instance |
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 | |
19768d67 |
146 | =item Moose::Cookbook::Meta::Recipe8 - Hooking into immutabilization (TODO) |
1acd5999 |
147 | |
148 | Moose has a feature known as "immutabilization". By calling C<< |
149 | __PACKAGE__->meta()->make_immutable() >> after defining your class |
150 | (attributes, roles, etc), you tell Moose to optimize things like |
151 | object creation, attribute access, and so on. |
152 | |
153 | If you are creating your own metaclasses, you may need to hook into |
154 | the immutabilization system. This cuts across a number of spots, |
155 | including the metaclass class, meta method classes, and possibly the |
156 | meta-instance class as well. |
157 | |
158 | This recipe shows you how to write extensions which immutabilize |
159 | properly. |
160 | |
49f6b0ac |
161 | =back |
162 | |
6fa0a13f |
163 | =head2 Extending Moose |
164 | |
4eec354b |
165 | These recipes cover some more ways to extend Moose, and will be useful |
166 | if you plan to write your own C<MooseX> module. |
167 | |
49f6b0ac |
168 | =over 4 |
169 | |
c8d5f1e1 |
170 | =item L<Moose::Cookbook::Extending::Recipe1> - Moose extension overview |
171 | |
dab94063 |
172 | There are quite a few ways to extend Moose. This recipe provides an |
173 | overview of each method, and provides recommendations for when each is |
174 | appropriate. |
c8d5f1e1 |
175 | |
f3ce0579 |
176 | =item L<Moose::Cookbook::Extending::Recipe2> - Providing a base object class role |
c8d5f1e1 |
177 | |
178 | Many base object class extensions can be implemented as roles. This |
f3ce0579 |
179 | example shows how to provide a base object class debugging role that |
180 | is applied to any class that uses a notional C<MooseX::Debugging> |
181 | module. |
c8d5f1e1 |
182 | |
183 | =item L<Moose::Cookbook::Extending::Recipe3> - Providing an alternate base object class |
6fa0a13f |
184 | |
185 | You may find that you want to provide an alternate base object class |
186 | along with a meta extension, or maybe you just want to add some |
187 | functionality to all your classes without typing C<extends |
188 | 'MyApp::Base'> over and over. |
189 | |
c8d5f1e1 |
190 | =item L<Moose::Cookbook::Extending::Recipe4> - Acting like Moose.pm and providing sugar Moose-style |
6fa0a13f |
191 | |
c5b9daec |
192 | This recipe shows how to provide a replacement for C<Moose.pm>. You |
193 | may want to do this as part of the API for a C<MooseX> module, |
5583dc1c |
194 | especially if you want to default to a new metaclass class or base |
195 | object class. |
6fa0a13f |
196 | |
cb2478d4 |
197 | =back |
198 | |
199 | =head1 SNACKS |
200 | |
201 | =over 4 |
202 | |
f4ebf54f |
203 | =item L<Moose::Cookbook::Snack::Keywords> |
204 | |
cb2478d4 |
205 | =item L<Moose::Cookbook::Snack::Types> |
206 | |
471c4f09 |
207 | =back |
208 | |
209 | =head1 SEE ALSO |
210 | |
211 | =over 4 |
212 | |
8bdc7f13 |
213 | =item L<http://www.gsph.com/index.php?Lang=En&ID=291> |
471c4f09 |
214 | |
215 | =back |
216 | |
f7f3648d |
217 | =cut |