Add built local::lib
[catagits/Gitalist.git] / local-lib5 / man / man3 / Moose::Cookbook.3pm
1 .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.3
2 .\"
3 .\" Standard preamble:
4 .\" ========================================================================
5 .de Sh \" Subsection heading
6 .br
7 .if t .Sp
8 .ne 5
9 .PP
10 \fB\\$1\fR
11 .PP
12 ..
13 .de Sp \" Vertical space (when we can't use .PP)
14 .if t .sp .5v
15 .if n .sp
16 ..
17 .de Vb \" Begin verbatim text
18 .ft CW
19 .nf
20 .ne \\$1
21 ..
22 .de Ve \" End verbatim text
23 .ft R
24 .fi
25 ..
26 .\" Set up some character translations and predefined strings.  \*(-- will
27 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28 .\" double quote, and \*(R" will give a right double quote.  | will give a
29 .\" real vertical bar.  \*(C+ will give a nicer C++.  Capital omega is used to
30 .\" do unbreakable dashes and therefore won't be available.  \*(C` and \*(C'
31 .\" expand to `' in nroff, nothing in troff, for use with C<>.
32 .tr \(*W-|\(bv\*(Tr
33 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34 .ie n \{\
35 .    ds -- \(*W-
36 .    ds PI pi
37 .    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38 .    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
39 .    ds L" ""
40 .    ds R" ""
41 .    ds C` ""
42 .    ds C' ""
43 'br\}
44 .el\{\
45 .    ds -- \|\(em\|
46 .    ds PI \(*p
47 .    ds L" ``
48 .    ds R" ''
49 'br\}
50 .\"
51 .\" If the F register is turned on, we'll generate index entries on stderr for
52 .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53 .\" entries marked with X<> in POD.  Of course, you'll have to process the
54 .\" output yourself in some meaningful fashion.
55 .if \nF \{\
56 .    de IX
57 .    tm Index:\\$1\t\\n%\t"\\$2"
58 ..
59 .    nr % 0
60 .    rr F
61 .\}
62 .\"
63 .\" For nroff, turn off justification.  Always turn off hyphenation; it makes
64 .\" way too many mistakes in technical documents.
65 .hy 0
66 .if n .na
67 .\"
68 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69 .\" Fear.  Run.  Save yourself.  No user-serviceable parts.
70 .    \" fudge factors for nroff and troff
71 .if n \{\
72 .    ds #H 0
73 .    ds #V .8m
74 .    ds #F .3m
75 .    ds #[ \f1
76 .    ds #] \fP
77 .\}
78 .if t \{\
79 .    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80 .    ds #V .6m
81 .    ds #F 0
82 .    ds #[ \&
83 .    ds #] \&
84 .\}
85 .    \" simple accents for nroff and troff
86 .if n \{\
87 .    ds ' \&
88 .    ds ` \&
89 .    ds ^ \&
90 .    ds , \&
91 .    ds ~ ~
92 .    ds /
93 .\}
94 .if t \{\
95 .    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96 .    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97 .    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98 .    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99 .    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100 .    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101 .\}
102 .    \" troff and (daisy-wheel) nroff accents
103 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110 .ds ae a\h'-(\w'a'u*4/10)'e
111 .ds Ae A\h'-(\w'A'u*4/10)'E
112 .    \" corrections for vroff
113 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115 .    \" for low resolution devices (crt and lpr)
116 .if \n(.H>23 .if \n(.V>19 \
117 \{\
118 .    ds : e
119 .    ds 8 ss
120 .    ds o a
121 .    ds d- d\h'-1'\(ga
122 .    ds D- D\h'-1'\(hy
123 .    ds th \o'bp'
124 .    ds Th \o'LP'
125 .    ds ae ae
126 .    ds Ae AE
127 .\}
128 .rm #[ #] #H #V #F C
129 .\" ========================================================================
130 .\"
131 .IX Title "Moose::Cookbook 3"
132 .TH Moose::Cookbook 3 "2009-05-05" "perl v5.8.7" "User Contributed Perl Documentation"
133 .SH "NAME"
134 Moose::Cookbook \- How to cook a Moose
135 .SH "DESCRIPTION"
136 .IX Header "DESCRIPTION"
137 The Moose cookbook is a series of recipes showing various Moose
138 features. Most recipes present some code demonstrating some feature,
139 and then explain the details of the code.
140 .PP
141 You should probably read the Moose::Manual first. The manual
142 explains Moose concepts without being too code\-heavy.
143 .SH "RECIPES"
144 .IX Header "RECIPES"
145 .Sh "Basic Moose"
146 .IX Subsection "Basic Moose"
147 These recipes will give you a good overview of Moose's capabilities, starting
148 with simple attribute declaration, and moving on to more powerful features like
149 laziness, types, type coercion, method modifiers, and more.
150 .IP "Moose::Cookbook::Basics::Recipe1 \- The (always classic) \fBPoint\fR example" 4
151 .IX Item "Moose::Cookbook::Basics::Recipe1 - The (always classic) Point example"
152 A simple Moose-based class. Demonstrates Moose attributes and subclassing.
153 .IP "Moose::Cookbook::Basics::Recipe2 \- A simple \fBBankAccount\fR example" 4
154 .IX Item "Moose::Cookbook::Basics::Recipe2 - A simple BankAccount example"
155 A slightly more complex Moose class. Demonstrates using a method
156 modifier in a subclass.
157 .IP "Moose::Cookbook::Basics::Recipe3 \- A lazy \fBBinaryTree\fR example" 4
158 .IX Item "Moose::Cookbook::Basics::Recipe3 - A lazy BinaryTree example"
159 Demonstrates several attribute features, including types, weak
160 references, predicates (\*(L"does this object have a foo?\*(R"), defaults,
161 laziness, and triggers.
162 .IP "Moose::Cookbook::Basics::Recipe4 \- Subtypes, and modeling a simple \fBCompany\fR class hierarchy" 4
163 .IX Item "Moose::Cookbook::Basics::Recipe4 - Subtypes, and modeling a simple Company class hierarchy"
164 Introduces the creation and use of custom types, a \f(CW\*(C`BUILD\*(C'\fR method,
165 and the use of \f(CW\*(C`override\*(C'\fR in a subclass.
166 .IP "Moose::Cookbook::Basics::Recipe5 \- More subtypes, coercion in a \fBRequest\fR class" 4
167 .IX Item "Moose::Cookbook::Basics::Recipe5 - More subtypes, coercion in a Request class"
168 More type examples, including the use of type coercions.
169 .IP "Moose::Cookbook::Basics::Recipe6 \- The augment/inner example" 4
170 .IX Item "Moose::Cookbook::Basics::Recipe6 - The augment/inner example"
171 Demonstrates the use of \f(CW\*(C`augment\*(C'\fR method modifiers, a way of turning
172 the usual method overriding style \*(L"inside\-out\*(R".
173 .IP "Moose::Cookbook::Basics::Recipe7 \- Making Moose fast with immutable" 4
174 .IX Item "Moose::Cookbook::Basics::Recipe7 - Making Moose fast with immutable"
175 Making a class immutable greatly increases the speed of accessors and
176 object construction.
177 .IP "Moose::Cookbook::Basics::Recipe8 \- Builder methods and lazy_build" 4
178 .IX Item "Moose::Cookbook::Basics::Recipe8 - Builder methods and lazy_build"
179 The builder feature provides an inheritable and role-composable way to
180 provide a default attribute value.
181 .IP "Moose::Cookbook::Basics::Recipe9 \- Operator overloading, subtypes, and coercion" 4
182 .IX Item "Moose::Cookbook::Basics::Recipe9 - Operator overloading, subtypes, and coercion"
183 Demonstrates using operator overloading, coercion, and subtypes to
184 model how eye color is determined during reproduction.
185 .IP "Moose::Cookbook::Basics::Recipe10 \- Using \s-1BUILDARGS\s0 and \s-1BUILD\s0 to hook into object construction" 4
186 .IX Item "Moose::Cookbook::Basics::Recipe10 - Using BUILDARGS and BUILD to hook into object construction"
187 This recipe demonstrates the use of \f(CW\*(C`BUILDARGS\*(C'\fR and \f(CW\*(C`BUILD\*(C'\fR to hook
188 into object construction.
189 .IP "Moose::Cookbook::Basics::Recipe11 \- Extending a non-Moose base class" 4
190 .IX Item "Moose::Cookbook::Basics::Recipe11 - Extending a non-Moose base class"
191 In this recipe, we make a Moose-based subclass of DateTime, a
192 module which does not use Moose itself.
193 .Sh "Moose Roles"
194 .IX Subsection "Moose Roles"
195 These recipes will show you how to use Moose roles.
196 .IP "Moose::Cookbook::Roles::Recipe1 \- The Moose::Role example" 4
197 .IX Item "Moose::Cookbook::Roles::Recipe1 - The Moose::Role example"
198 Demonstrates roles, which are also sometimes known as traits or
199 mix\-ins. Roles provide a method of code re-use which is orthogonal to
200 subclassing.
201 .IP "Moose::Cookbook::Roles::Recipe2 \- Advanced Role Composition \- method exclusion and aliasing" 4
202 .IX Item "Moose::Cookbook::Roles::Recipe2 - Advanced Role Composition - method exclusion and aliasing"
203 Sometimes you just want to include part of a role in your
204 class. Sometimes you want the whole role but one of its methods
205 conflicts with one in your class. With method exclusion and aliasing,
206 you can work around these problems.
207 .IP "Moose::Cookbook::Roles::Recipe3 \- Applying a role to an object instance" 4
208 .IX Item "Moose::Cookbook::Roles::Recipe3 - Applying a role to an object instance"
209 In this recipe, we apply a role to an existing object instance.
210 .Sh "Meta Moose"
211 .IX Subsection "Meta Moose"
212 These recipes show you how to write your own meta classes, which lets
213 you extend the object system provided by Moose.
214 .IP "Moose::Cookbook::Meta::Recipe1 \- Welcome to the meta-world (Why Go Meta?)" 4
215 .IX Item "Moose::Cookbook::Meta::Recipe1 - Welcome to the meta-world (Why Go Meta?)"
216 If you're wondering what all this \*(L"meta\*(R" stuff is, and why you should
217 care about it, read this \*(L"recipe\*(R".
218 .IP "Moose::Cookbook::Meta::Recipe2 \- A meta\-attribute, attributes with labels" 4
219 .IX Item "Moose::Cookbook::Meta::Recipe2 - A meta-attribute, attributes with labels"
220 One way to extend Moose is to provide your own attribute
221 metaclasses. Attribute metaclasses let you extend attribute
222 declarations (with \f(CW\*(C`has\*(C'\fR) and behavior to provide additional
223 attribute functionality.
224 .IP "Moose::Cookbook::Meta::Recipe3 \- Labels implemented via attribute traits" 4
225 .IX Item "Moose::Cookbook::Meta::Recipe3 - Labels implemented via attribute traits"
226 Extending Moose's attribute metaclass is a great way to add
227 functionality. However, attributes can only have one metaclass.
228 Applying roles to the attribute metaclass lets you provide
229 composable attribute functionality.
230 .ie n .IP "Moose::Cookbook::Meta::Recipe4 \- Adding a ""table"" attribute to the metaclass" 4
231 .el .IP "Moose::Cookbook::Meta::Recipe4 \- Adding a ``table'' attribute to the metaclass" 4
232 .IX Item "Moose::Cookbook::Meta::Recipe4 - Adding a table attribute to the metaclass"
233 If you want to store more information about your classes, you'll have
234 to extend \f(CW\*(C`Moose::Meta::Class\*(C'\fR. Doing so is simple, but you'll
235 probably also want to provide some sugar, so see
236 Moose::Cookbook::Extending::Recipe2 as well.
237 .ie n .IP "Moose::Cookbook::Meta::Recipe5 \- The ""table"" attribute implemented as a metaclass trait" 4
238 .el .IP "Moose::Cookbook::Meta::Recipe5 \- The ``table'' attribute implemented as a metaclass trait" 4
239 .IX Item "Moose::Cookbook::Meta::Recipe5 - The table attribute implemented as a metaclass trait"
240 This recipe takes the class metaclass we saw in the previous recipe
241 and reimplements it as a metaclass trait.
242 .IP "Moose::Cookbook::Meta::Recipe6 \- A method metaclass for marking methods public or private" 4
243 .IX Item "Moose::Cookbook::Meta::Recipe6 - A method metaclass for marking methods public or private"
244 This recipe shows a custom method metaclass that implements making a
245 method private.
246 .IP "Moose::Cookbook::Meta::Recipe7 \- Using a blessed array reference as an object instance" 4
247 .IX Item "Moose::Cookbook::Meta::Recipe7 - Using a blessed array reference as an object instance"
248 This recipe shows an example of how you create your own meta-instance
249 class. The meta-instance determines the internal structure of object
250 instances and provide access to attribute slots.
251 .IP "Moose::Cookbook::Meta::Recipe8 \- Hooking into immutabilization (\s-1TODO\s0)" 4
252 .IX Item "Moose::Cookbook::Meta::Recipe8 - Hooking into immutabilization (TODO)"
253 Moose has a feature known as \*(L"immutabilization\*(R". By calling \f(CW\*(C`_\|_PACKAGE_\|_\->meta()\->make_immutable()\*(C'\fR after defining your class
254 (attributes, roles, etc), you tell Moose to optimize things like
255 object creation, attribute access, and so on.
256 .Sp
257 If you are creating your own metaclasses, you may need to hook into
258 the immutabilization system. This cuts across a number of spots,
259 including the metaclass class, meta method classes, and possibly the
260 meta-instance class as well.
261 .Sp
262 This recipe shows you how to write extensions which immutabilize
263 properly.
264 .Sh "Extending Moose"
265 .IX Subsection "Extending Moose"
266 These recipes cover some more ways to extend Moose, and will be useful
267 if you plan to write your own \f(CW\*(C`MooseX\*(C'\fR module.
268 .IP "Moose::Cookbook::Extending::Recipe1 \- Moose extension overview" 4
269 .IX Item "Moose::Cookbook::Extending::Recipe1 - Moose extension overview"
270 There are quite a few ways to extend Moose. This recipe provides an
271 overview of each method, and provides recommendations for when each is
272 appropriate.
273 .IP "Moose::Cookbook::Extending::Recipe2 \- Providing a base object class role" 4
274 .IX Item "Moose::Cookbook::Extending::Recipe2 - Providing a base object class role"
275 Many base object class extensions can be implemented as roles. This
276 example shows how to provide a base object class debugging role that
277 is applied to any class that uses a notional \f(CW\*(C`MooseX::Debugging\*(C'\fR
278 module.
279 .IP "Moose::Cookbook::Extending::Recipe3 \- Providing an alternate base object class" 4
280 .IX Item "Moose::Cookbook::Extending::Recipe3 - Providing an alternate base object class"
281 You may find that you want to provide an alternate base object class
282 along with a meta extension, or maybe you just want to add some
283 functionality to all your classes without typing \f(CW\*(C`extends
284 \&'MyApp::Base'\*(C'\fR over and over.
285 .IP "Moose::Cookbook::Extending::Recipe4 \- Acting like Moose.pm and providing sugar Moose-style" 4
286 .IX Item "Moose::Cookbook::Extending::Recipe4 - Acting like Moose.pm and providing sugar Moose-style"
287 This recipe shows how to provide a replacement for \f(CW\*(C`Moose.pm\*(C'\fR. You
288 may want to do this as part of the \s-1API\s0 for a \f(CW\*(C`MooseX\*(C'\fR module,
289 especially if you want to default to a new metaclass class or base
290 object class.
291 .SH "SNACKS"
292 .IX Header "SNACKS"
293 .IP "Moose::Cookbook::Snack::Keywords" 4
294 .IX Item "Moose::Cookbook::Snack::Keywords"
295 .PD 0
296 .IP "Moose::Cookbook::Snack::Types" 4
297 .IX Item "Moose::Cookbook::Snack::Types"
298 .PD
299 .SH "SEE ALSO"
300 .IX Header "SEE ALSO"
301 .IP "<http://www.gsph.com/index.php?Lang=En&ID=291>" 4
302 .IX Item "<http://www.gsph.com/index.php?Lang=En&ID=291>"
303 .SH "AUTHOR"
304 .IX Header "AUTHOR"
305 Stevan Little <stevan@iinteractive.com>
306 .SH "COPYRIGHT AND LICENSE"
307 .IX Header "COPYRIGHT AND LICENSE"
308 Copyright 2006\-2009 by Infinity Interactive, Inc.
309 .PP
310 <http://www.iinteractive.com>
311 .PP
312 This library is free software; you can redistribute it and/or modify
313 it under the same terms as Perl itself.