ToInstance no longer needs to subclass ToClass
[gitmo/Moose.git] / lib / Moose / Manual / Classes.pod
index d91e41a..8962c97 100644 (file)
@@ -31,12 +31,12 @@ example, you might define an attribute ...
 Attributes are described in the L<Moose::Manual::Attributes>
 documentation.
 
-Loading Moose also turns enables C<strict> and C<warnings> pragmas in
-your class.
+Loading Moose also enables C<strict> and C<warnings> pragmas in your
+class.
 
 When you load Moose, your class will become a subclass of
 L<Moose::Object>. The L<Moose::Object> class provides a default
-constructor, destructor, as well as object construction helper
+constructor and destructor, as well as object construction helper
 methods. You can read more about this in the
 L<Moose::Manual::Construction> document.
 
@@ -66,7 +66,7 @@ classes, C<extends>:
 
   has 'username' => ( is => 'rw' );
 
-ote, that each call to C<extends> will I<reset> your parents. For
+Note that each call to C<extends> will I<reset> your parents. For
 multiple inheritance you must provide all the parents at once,
 C<extends 'Foo', 'Bar'>.
 
@@ -83,16 +83,28 @@ namespace. We recommend that you take advantage of this feature, since
 it just makes your classes "cleaner". You can do this by simply adding
 C<no Moose> at the end of your module file.
 
+  package Person;
+
+  use Moose;
+
+  has 'ssn' => ( is => 'rw' );
+
+  no Moose;
+
 This deletes Moose's sugar functions from your class's namespace, so
 that C<< Person->can('has') >> will no longer return true.
 
+A more generic way to unimport not only L<Moose>'s exports but also
+those from type libraries and other modules is to use
+L<namespace::clean> or L<namespace::autoclean>.
+
 =head1 MAKING IT FASTER
 
 Moose has a feature called "immutabilization" that you can use to
 greatly speed up your classes at runtime. However, using it does incur
 a cost when your class is first being loaded. When you make your class
 immutable you tell Moose that you will not be changing it in the
-future. You will not adding any more attributes, methods, roles, etc.
+future. You will not be adding any more attributes, methods, roles, etc.
 
 This allows Moose to generate code specific to your class. In
 particular, it creates an "inline" constructor, making object
@@ -103,6 +115,18 @@ class's metaclass object.
 
   __PACKAGE__->meta->make_immutable;
 
+=head2 Immutabilization and C<new()>
+
+If you override C<new()> in your class, then the immutabilization code
+will not be able to provide an optimized constructor for your
+class. Instead, you should use a C<BUILD()> method, which will be
+called from the inlined constructor.
+
+Alternately, if you really need to provide a different C<new()>, you
+can also provide your own immutabilization method. Doing so requires
+extending the Moose metaclasses, and is well beyond the scope of this
+manual.
+
 =head1 AUTHOR
 
 Dave Rolsky E<lt>autarch@urth.orgE<gt>