Add built local::lib
[catagits/Gitalist.git] / local-lib5 / man / man3 / Moose::Manual::FAQ.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::Manual::FAQ 3"
132 .TH Moose::Manual::FAQ 3 "2009-07-08" "perl v5.8.7" "User Contributed Perl Documentation"
133 .SH "NAME"
134 Moose::Manual::FAQ \- Frequently asked questions about Moose
135 .SH "FREQUENTLY ASKED QUESTIONS"
136 .IX Header "FREQUENTLY ASKED QUESTIONS"
137 .Sh "Module Stability"
138 .IX Subsection "Module Stability"
139 \fIIs Moose \*(L"production ready\*(R"?\fR
140 .IX Subsection "Is Moose production ready?"
141 .PP
142 Yes! Many sites with household names are using Moose to build
143 high-traffic services. Countless others are using Moose in production.
144 .PP
145 As of this writing, Moose is a dependency of several hundred \s-1CPAN\s0
146 modules. <http://cpants.perl.org/dist/used_by/Moose>
147 .PP
148 \fIIs Moose's \s-1API\s0 stable?\fR
149 .IX Subsection "Is Moose's API stable?"
150 .PP
151 Yes. The sugary \s-1API\s0, the one 95% of users will interact with, is
152 \&\fBvery stable\fR. Any changes will be \fB100% backwards compatible\fR.
153 .PP
154 The meta \s-1API\s0 is less set in stone. We reserve the right to tweak
155 parts of it to improve efficiency or consistency. This will not be
156 done lightly. We do perform deprecation cycles. We \fIreally\fR
157 do not like making ourselves look bad by breaking your code.
158 Submitting test cases is the best way to ensure that your code is not
159 inadvertently broken by refactoring.
160 .PP
161 \fII heard Moose is slow, is this true?\fR
162 .IX Subsection "I heard Moose is slow, is this true?"
163 .PP
164 Again, this one is tricky, so Yes \fIand\fR No.
165 .PP
166 Firstly, \fInothing\fR in life is free, and some Moose features do cost
167 more than others. It is also the policy of Moose to \fBonly charge you
168 for the features you use\fR, and to do our absolute best to not place
169 any extra burdens on the execution of your code for features you are
170 not using. Of course using Moose itself does involve some overhead,
171 but it is mostly compile time. At this point we do have some options
172 available for getting the speed you need.
173 .PP
174 Currently we provide the option of making your classes immutable as a
175 means of boosting speed. This will mean a slightly larger compile time
176 cost, but the runtime speed increase (especially in object
177 construction) is pretty significant. This can be done with the
178 following code:
179 .PP
180 .Vb 1
181 \&  MyClass\->meta\->make_immutable();
182 .Ve
183 .PP
184 We are regularly converting the hotspots of Class::MOP to \s-1XS\s0.
185 Florian Ragwitz and Yuval Kogman are currently working on a way to
186 compile your accessors and instances directly into C, so that everyone
187 can enjoy blazing fast \s-1OO\s0.
188 .PP
189 \fIWhen will Moose 1.0 be ready?\fR
190 .IX Subsection "When will Moose 1.0 be ready?"
191 .PP
192 Moose is ready now! Stevan Little declared 0.18, released in March
193 2007, to be \*(L"ready to use\*(R".
194 .Sh "Constructors"
195 .IX Subsection "Constructors"
196 \fIHow do I write custom constructors with Moose?\fR
197 .IX Subsection "How do I write custom constructors with Moose?"
198 .PP
199 Ideally, you should never write your own \f(CW\*(C`new\*(C'\fR method, and should use
200 Moose's other features to handle your specific object construction
201 needs. Here are a few scenarios, and the Moose way to solve them;
202 .PP
203 If you need to call initialization code post instance construction,
204 then use the \f(CW\*(C`BUILD\*(C'\fR method. This feature is taken directly from Perl
205 6. Every \f(CW\*(C`BUILD\*(C'\fR method in your inheritance chain is called (in the
206 correct order) immediately after the instance is constructed.  This
207 allows you to ensure that all your superclasses are initialized
208 properly as well. This is the best approach to take (when possible)
209 because it makes subclassing your class much easier.
210 .PP
211 If you need to affect the constructor's parameters prior to the
212 instance actually being constructed, you have a number of options.
213 .PP
214 To change the parameter processing as a whole, you can use the
215 \&\f(CW\*(C`BUILDARGS\*(C'\fR method. The default implementation accepts key/value
216 pairs or a hash reference. You can override it to take positional
217 args, or any other format
218 .PP
219 To change the handling of individual parameters, there are
220 \&\fIcoercions\fR (See the Moose::Cookbook::Basics::Recipe5 for a
221 complete example and explanation of coercions). With coercions it is
222 possible to morph argument values into the correct expected
223 types. This approach is the most flexible and robust, but does have a
224 slightly higher learning curve.
225 .PP
226 \fIHow do I make non-Moose constructors work with Moose?\fR
227 .IX Subsection "How do I make non-Moose constructors work with Moose?"
228 .PP
229 Usually the correct approach to subclassing a non-Moose class is
230 delegation.  Moose makes this easy using the \f(CW\*(C`handles\*(C'\fR keyword,
231 coercions, and \f(CW\*(C`lazy_build\*(C'\fR, so subclassing is often not the ideal
232 route.
233 .PP
234 That said, if you really need to inherit from a non-Moose class, see
235 Moose::Cookbook::Basics::Recipe11 for an example of how to do it,
236 or take a look at \*(L"MooseX::NonMoose\*(R" in Moose::Manual::MooseX.
237 .Sh "Accessors"
238 .IX Subsection "Accessors"
239 \fIHow do I tell Moose to use get/set accessors?\fR
240 .IX Subsection "How do I tell Moose to use get/set accessors?"
241 .PP
242 The easiest way to accomplish this is to use the \f(CW\*(C`reader\*(C'\fR and
243 \&\f(CW\*(C`writer\*(C'\fR attribute options:
244 .PP
245 .Vb 5
246 \&  has 'bar' => (
247 \&      isa    => 'Baz',
248 \&      reader => 'get_bar',
249 \&      writer => 'set_bar',
250 \&  );
251 .Ve
252 .PP
253 Moose will still take advantage of type constraints, triggers, etc.
254 when creating these methods.
255 .PP
256 If you do not like this much typing, and wish it to be a default for
257 your classes, please see MooseX::FollowPBP. This extension will
258 allow you to write:
259 .PP
260 .Vb 4
261 \&  has 'bar' => (
262 \&      isa => 'Baz',
263 \&      is  => 'rw',
264 \&  );
265 .Ve
266 .PP
267 Moose will create separate \f(CW\*(C`get_bar\*(C'\fR and \f(CW\*(C`set_bar\*(C'\fR methods instead
268 of a single \f(CW\*(C`bar\*(C'\fR method.
269 .PP
270 If you like \f(CW\*(C`bar\*(C'\fR and \f(CW\*(C`set_bar\*(C'\fR, see
271 MooseX::SemiAffordanceAccessor.
272 .PP
273 \&\s-1NOTE:\s0 This \fBcannot\fR be set globally in Moose, as that would break
274 other classes which are built with Moose. You can still save on typing
275 by defining a new MyApp::Moose that exports Moose's sugar and then
276 turns on MooseX::FollowPBP. See
277 Moose::Cookbook::Extending::Recipe4.
278 .PP
279 \fIHow can I inflate/deflate values in accessors?\fR
280 .IX Subsection "How can I inflate/deflate values in accessors?"
281 .PP
282 Well, the first question to ask is if you actually need both inflate
283 and deflate.
284 .PP
285 If you only need to inflate, then we suggest using coercions. Here is
286 some basic sample code for inflating a DateTime object:
287 .PP
288 .Vb 1
289 \&  class_type 'DateTime';
290 .Ve
291 .PP
292 .Vb 3
293 \&  coerce 'DateTime'
294 \&      => from 'Str'
295 \&      => via { DateTime::Format::MySQL\->parse_datetime($_) };
296 .Ve
297 .PP
298 .Vb 1
299 \&  has 'timestamp' => (is => 'rw', isa => 'DateTime', coerce => 1);
300 .Ve
301 .PP
302 This creates a custom type for DateTime objects, then attaches
303 a coercion to that type. The \f(CW\*(C`timestamp\*(C'\fR attribute is then told
304 to expect a \f(CW\*(C`DateTime\*(C'\fR type, and to try to coerce it. When a \f(CW\*(C`Str\*(C'\fR
305 type is given to the \f(CW\*(C`timestamp\*(C'\fR accessor, it will attempt to
306 coerce the value into a \f(CW\*(C`DateTime\*(C'\fR object using the code in found
307 in the \f(CW\*(C`via\*(C'\fR block.
308 .PP
309 For a more comprehensive example of using coercions, see the
310 Moose::Cookbook::Basics::Recipe5.
311 .PP
312 If you need to deflate your attribute's value, the current best
313 practice is to add an \f(CW\*(C`around\*(C'\fR modifier to your accessor:
314 .PP
315 .Vb 3
316 \&  # a timestamp which stores as
317 \&  # seconds from the epoch
318 \&  has 'timestamp' => (is => 'rw', isa => 'Int');
319 .Ve
320 .PP
321 .Vb 3
322 \&  around 'timestamp' => sub {
323 \&      my $next = shift;
324 \&      my $self = shift;
325 .Ve
326 .PP
327 .Vb 1
328 \&      return $self\->$next unless @_;
329 .Ve
330 .PP
331 .Vb 4
332 \&      # assume we get a DateTime object ...
333 \&      my $timestamp = shift;
334 \&      return $self\->$next( $timestamp\->epoch );
335 \&  };
336 .Ve
337 .PP
338 It is also possible to do deflation using coercion, but this tends to
339 get quite complex and require many subtypes. An example of this is
340 outside the scope of this document, ask on #moose or send a mail to
341 the list.
342 .PP
343 Still another option is to write a custom attribute metaclass, which
344 is also outside the scope of this document, but we would be happy to
345 explain it on #moose or the mailing list.
346 .PP
347 \fII created an attribute, where are my accessors?\fR
348 .IX Subsection "I created an attribute, where are my accessors?"
349 .PP
350 Accessors are \fBnot\fR created implicitly, you \fBmust\fR ask Moose to
351 create them for you. My guess is that you have this:
352 .PP
353 .Vb 1
354 \&  has 'foo' => (isa => 'Bar');
355 .Ve
356 .PP
357 when what you really want to say is:
358 .PP
359 .Vb 1
360 \&  has 'foo' => (isa => 'Bar', is => 'rw');
361 .Ve
362 .PP
363 The reason this is so is because it is a perfectly valid use case to
364 \&\fInot\fR have an accessor. The simplest one is that you want to write
365 your own. If Moose created one automatically, then because of the
366 order in which classes are constructed, Moose would overwrite your
367 custom accessor. You wouldn't want that would you?
368 .Sh "Method Modifiers"
369 .IX Subsection "Method Modifiers"
370 \fIHow can I affect the values in \f(CI@_\fI using \f(CI\*(C`before\*(C'\fI?\fR
371 .IX Subsection "How can I affect the values in @_ using before?"
372 .PP
373 You can't, actually: \f(CW\*(C`before\*(C'\fR only runs before the main method, and
374 it cannot easily affect the method's execution.
375 .PP
376 You similarly can't use \f(CW\*(C`after\*(C'\fR to affect the return value of a
377 method.
378 .PP
379 We limit \f(CW\*(C`before\*(C'\fR and \f(CW\*(C`after\*(C'\fR because this lets you write more
380 concise code. You do not have to worry about passing \f(CW@_\fR to the
381 original method, or forwarding its return value (being careful to
382 preserve context).
383 .PP
384 The \f(CW\*(C`around\*(C'\fR method modifier has neither of these limitations, but is
385 a little more verbose.
386 .PP
387 \fICan I use \f(CI\*(C`before\*(C'\fI to stop execution of a method?\fR
388 .IX Subsection "Can I use before to stop execution of a method?"
389 .PP
390 Yes, but only if you throw an exception. If this is too drastic a
391 measure then we suggest using \f(CW\*(C`around\*(C'\fR instead. The \f(CW\*(C`around\*(C'\fR method
392 modifier is the only modifier which can gracefully prevent execution
393 of the main method. Here is an example:
394 .PP
395 .Vb 8
396 \&    around 'baz' => sub {
397 \&        my $next = shift;
398 \&        my ($self, %options) = @_;
399 \&        unless ($options\->{bar} eq 'foo') {
400 \&            return 'bar';
401 \&        }
402 \&        $self\->$next(%options);
403 \&    };
404 .Ve
405 .PP
406 By choosing not to call the \f(CW$next\fR method, you can stop the
407 execution of the main method.
408 .PP
409 \fIWhy can't I see return values in an \f(CI\*(C`after\*(C'\fI modifier?\fR
410 .IX Subsection "Why can't I see return values in an after modifier?"
411 .PP
412 As with the \f(CW\*(C`before\*(C'\fR modifier, the \f(CW\*(C`after\*(C'\fR modifier is simply called
413 \&\fIafter\fR the main method. It is passed the original contents of \f(CW@_\fR
414 and \fBnot\fR the return values of the main method.
415 .PP
416 Again, the arguments are too lengthy as to why this has to be. And as
417 with \f(CW\*(C`before\*(C'\fR I recommend using an \f(CW\*(C`around\*(C'\fR modifier instead.  Here
418 is some sample code:
419 .PP
420 .Vb 7
421 \&  around 'foo' => sub {
422 \&      my $next = shift;
423 \&      my ($self, @args) = @_;
424 \&      my @rv = $next\->($self, @args);
425 \&      # do something silly with the return values
426 \&      return reverse @rv;
427 \&  };
428 .Ve
429 .Sh "Type Constraints"
430 .IX Subsection "Type Constraints"
431 \fIHow can I provide a custom error message for a type constraint?\fR
432 .IX Subsection "How can I provide a custom error message for a type constraint?"
433 .PP
434 Use the \f(CW\*(C`message\*(C'\fR option when building the subtype:
435 .PP
436 .Vb 4
437 \&  subtype 'NaturalLessThanTen'
438 \&      => as 'Natural'
439 \&      => where { $_ < 10 }
440 \&      => message { "This number ($_) is not less than ten!" };
441 .Ve
442 .PP
443 This \f(CW\*(C`message\*(C'\fR block will be called when a value fails to pass the
444 \&\f(CW\*(C`NaturalLessThanTen\*(C'\fR constraint check.
445 .PP
446 \fICan I turn off type constraint checking?\fR
447 .IX Subsection "Can I turn off type constraint checking?"
448 .PP
449 Not yet. This option may come in a future release.
450 .PP
451 \fIMy coercions stopped working with recent Moose, why did you break it?\fR
452 .IX Subsection "My coercions stopped working with recent Moose, why did you break it?"
453 .PP
454 Moose 0.76 fixed a case where Coercions were being applied even if the original constraint passed. This has caused some edge cases to fail where people were doing something like
455 .PP
456 .Vb 2
457 \&    subtype Address => as 'Str';
458 \&    coerce Address => from Str => via { get_address($_) };
459 .Ve
460 .PP
461 Which is not what they intended. The Type Constraint \f(CW\*(C`Address\*(C'\fR is too loose in this case, it is saying that all Strings are Addresses, which is obviously not the case. The solution is to provide a where clause that properly restricts the Type Constraint.
462 .PP
463 .Vb 1
464 \&    subtype Address => as Str => where { looks_like_address($_) };
465 .Ve
466 .PP
467 This will allow the coercion to apply only to strings that fail to look like an Address.
468 .Sh "Roles"
469 .IX Subsection "Roles"
470 \fIWhy is \s-1BUILD\s0 not called for my composed roles?\fR
471 .IX Subsection "Why is BUILD not called for my composed roles?"
472 .PP
473 \&\f(CW\*(C`BUILD\*(C'\fR is never called in composed roles. The primary reason is that
474 roles are \fBnot\fR order sensitive. Roles are composed in such a way
475 that the order of composition does not matter (for information on the
476 deeper theory of this read the original traits papers here
477 <http://www.iam.unibe.ch/~scg/Research/Traits/>).
478 .PP
479 Because roles are essentially unordered, it would be impossible to
480 determine the order in which to execute the \f(CW\*(C`BUILD\*(C'\fR methods.
481 .PP
482 As for alternate solutions, there are a couple.
483 .IP "\(bu" 4
484 Using a combination of lazy and default in your attributes to defer
485 initialization (see the Binary Tree example in the cookbook for a good
486 example of lazy/default usage Moose::Cookbook::Basics::Recipe3)
487 .IP "\(bu" 4
488 Use attribute triggers, which fire after an attribute is set, to
489 facilitate initialization. These are described in the Moose docs,
490 and examples can be found in the test suite.
491 .PP
492 In general, roles should not \fIrequire\fR initialization; they should
493 either provide sane defaults or should be documented as needing
494 specific initialization. One such way to \*(L"document\*(R" this is to have a
495 separate attribute initializer which is required for the role. Here is
496 an example of how to do this:
497 .PP
498 .Vb 2
499 \&  package My::Role;
500 \&  use Moose::Role;
501 .Ve
502 .PP
503 .Vb 9
504 \&  has 'height' => (
505 \&      is      => 'rw',
506 \&      isa     => 'Int',
507 \&      lazy    => 1,
508 \&      default => sub {
509 \&          my $self = shift;
510 \&          $self\->init_height;
511 \&      }
512 \&  );
513 .Ve
514 .PP
515 .Vb 1
516 \&  requires 'init_height';
517 .Ve
518 .PP
519 In this example, the role will not compose successfully unless the
520 class provides a \f(CW\*(C`init_height\*(C'\fR method.
521 .PP
522 If none of those solutions work, then it is possible that a role is
523 not the best tool for the job, and you really should be using
524 classes. Or, at the very least, you should reduce the amount of
525 functionality in your role so that it does not require initialization.
526 .PP
527 \fIWhat are Traits, and how are they different from Roles?\fR
528 .IX Subsection "What are Traits, and how are they different from Roles?"
529 .PP
530 In Moose, a trait is almost exactly the same thing as a role, except
531 that traits typically register themselves, which allows you to refer
532 to them by a short name (\*(L"Big\*(R" vs \*(L"MyApp::Role::Big\*(R").
533 .PP
534 In Moose\-speak, a \fIRole\fR is usually composed into a \fIclass\fR at
535 compile time, whereas a \fITrait\fR is usually composed into an instance
536 of a class at runtime to add or modify the behavior of \fBjust that
537 instance\fR.
538 .PP
539 Outside the context of Moose, traits and roles generally mean exactly
540 the same thing. The original paper called them Traits, however Perl 6
541 will call them Roles.
542 .Sh "Moose and Subroutine Attributes"
543 .IX Subsection "Moose and Subroutine Attributes"
544 \fIWhy don't subroutine attributes I inherited from a superclass work?\fR
545 .IX Subsection "Why don't subroutine attributes I inherited from a superclass work?"
546 .PP
547 Currently when you subclass a module, this is done at runtime with the
548 \&\f(CW\*(C`extends\*(C'\fR keyword but attributes are checked at compile time by
549 Perl. To make attributes work, you must place \f(CW\*(C`extends\*(C'\fR in a \f(CW\*(C`BEGIN\*(C'\fR
550 block so that the attribute handlers will be available at compile time
551 like this:
552 .PP
553 .Vb 1
554 \&  BEGIN { extends qw/Foo/ }
555 .Ve
556 .PP
557 Note that we're talking about Perl's subroutine attributes here, not
558 Moose attributes:
559 .PP
560 .Vb 1
561 \&  sub foo : Bar(27) { ... }
562 .Ve
563 .SH "AUTHOR"
564 .IX Header "AUTHOR"
565 Stevan Little <stevan@iinteractive.com>
566 .SH "COPYRIGHT AND LICENSE"
567 .IX Header "COPYRIGHT AND LICENSE"
568 Copyright 2006\-2009 by Infinity Interactive, Inc.
569 .PP
570 <http://www.iinteractive.com>
571 .PP
572 This library is free software; you can redistribute it and/or modify
573 it under the same terms as Perl itself.