fixing bug
[gitmo/Moose.git] / lib / Moose / Cookbook / FAQ.pod
index ead3438..5fd9f78 100644 (file)
@@ -11,11 +11,11 @@ Moose::Cookbook::FAQ - Frequently asked questions about Moose
 
 =head3 Is Moose "production ready"?
 
-Yes. I have three medium-to-large-ish web applications in 
+Yes. I have several medium-to-large-ish web applications in 
 production using Moose, they have been running without 
-issue now for almost a year. 
+issue now for well over a year. 
 
-At $work we are re-writing our core offering to use Moose, 
+At C<$work> we are re-writing our core offering to use Moose, 
 so it's continued development is assured. 
 
 Several other people on #moose either have apps in production 
@@ -44,7 +44,7 @@ is mostly compile time. At this point we do have some options
 available for getting the speed you need. 
 
 Currently we have the option of making your classes immutable 
-as a means of boosting speed. This will mean a larger compile 
+as a means of boosting speed. This will mean a slightly larger compile 
 time cost, but the runtime speed increase (especially in object
 construction) is pretty significant. This is not very well 
 documented yet, so please ask on the list or on #moose for more
@@ -57,10 +57,7 @@ conversion to XS.
 
 =head3 When will Moose 1.0 be ready?
 
-It is right now, I just haven't bumped the version number up yet.
-
-I still have some more internal TODO items I would like to complete
-before I would even consider bumping it to 1.0.
+It is right now, I declared 0.18 to be "ready to use".
 
 =head2 Constructors
 
@@ -81,36 +78,35 @@ because it makes sub classing your class much easier.
 If you need to affect the constructor's parameters prior to the 
 instance actually being constructed, you have a number of options.
 
-First, there are I<coercions> (See the L<Moose::Cookbook::Recipe5> 
-for a complete example and explaination of coercions). With 
-coercions it is possible to morph argument values into the correct 
-expected types. This approach is the most flexible and robust, but 
-does have a slightly higher learning curve.
+To change the parameter processing as a whole, you can use
+the C<BUILDARGS> method. The default implementation accepts key/value
+pairs or a hash reference. You can override it to take positional args,
+or any other format
 
-Second, using an C<around> method modifier on C<new> can be an 
-effective way to affect the contents of C<@_> prior to letting 
-Moose deal with it. This carries with it the extra burden for 
-your subclasses, in that they have to be sure to explicitly 
-call your C<new> and/or work around your C<new> to get to the 
-version from L<Moose::Object>. 
+To change the handling of individual parameters, there are I<coercions>
+(See the L<Moose::Cookbook::Recipe5> for a complete example and
+explaination of coercions). With coercions it is possible to morph
+argument values into the correct expected types. This approach is the
+most flexible and robust, but does have a slightly higher learning
+curve.
 
-The last approach is to use the standard Perl technique of calling 
-the C<SUPER::new> within your own custom version of C<new>. This, 
-of course, brings with it all the issues of the C<around> solution 
-as well as any issues C<SUPER::> might add.
+=head3 How do I make non-Moose constructors work with Moose? 
 
-In short, try to use C<BUILD> and coercions, they are your best 
-bets.
+Usually the correct approach to subclassing a non Moose class is
+delegation.  Moose makes this easy using the C<handles> keyword,
+coercions, and C<lazy_build>, so subclassing is often not the
+ideal route.
 
-=head3 How do I make non-Moose constructors work with Moose? 
+That said, the default Moose constructors is inherited from
+L<Moose::Object>. When inheriting from a non-Moose class, the
+inheritance chain to L<Moose::Object> is broken. The simplest way
+to fix this is to simply explicitly inherit from L<Moose::Object>
+yourself.
 
-Moose provides its own constructor, but it does it by making all 
-Moose-based classes inherit from L<Moose::Object>. When inheriting
-from a non-Moose class, the inheritance chain to L<Moose::Object> 
-is broken. The simplest way to fix this is to simply explicitly 
-inherit from L<Moose::Object> yourself. However, this does not 
-always fix the issue of a constructor. Here is a basic example of 
-how this can be worked around:
+However, this does not always fix the issue of actually calling the Moose
+constructor. Fortunately L<Class::MOP::Class/new_object>, the low level
+constructor, accepts the special C<__INSTANCE__> parameter, allowing you to
+instantiate your Moose attributes:
 
   package My::HTML::Template;
   use Moose;
@@ -126,13 +122,17 @@ how this can be worked around:
       return $class->meta->new_object(
           # pass in the constructed object
           # using the special key __INSTANCE__
-          __INSTANCE__ => $obj, @_
+          __INSTANCE__ => $obj,
+          @_, # pass in the normal args
       );
   }
 
 Of course, this only works if both your Moose class and the 
 inherited non-Moose class use the same instance type (typically 
-HASH refs). 
+HASH refs).
+
+Note that this doesn't call C<BUILDALL> automatically, you must do that
+yourself.
 
 Other techniques can be used as well, such as creating the object 
 using C<Moose::Object::new>, but calling the inherited non-Moose 
@@ -295,4 +295,4 @@ L<http://www.iinteractive.com>
 This library is free software; you can redistribute it and/or modify
 it under the same terms as Perl itself.
 
-=cut
\ No newline at end of file
+=cut