X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FManual%2FClasses.pod;h=8962c9756c5a02b71ff28a6d6c23cbd675c5221b;hb=d5f016af3d56eec870efee8858352a4014879be2;hp=d91e41a0b6c80879c7c5716d04abf0d298fe3239;hpb=3ac9038a977ef158b435c53622b83cc7b7c84a44;p=gitmo%2FMoose.git diff --git a/lib/Moose/Manual/Classes.pod b/lib/Moose/Manual/Classes.pod index d91e41a..8962c97 100644 --- a/lib/Moose/Manual/Classes.pod +++ b/lib/Moose/Manual/Classes.pod @@ -31,12 +31,12 @@ example, you might define an attribute ... Attributes are described in the L documentation. -Loading Moose also turns enables C and C pragmas in -your class. +Loading Moose also enables C and C pragmas in your +class. When you load Moose, your class will become a subclass of L. The L 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 document. @@ -66,7 +66,7 @@ classes, C: has 'username' => ( is => 'rw' ); -ote, that each call to C will I your parents. For +Note that each call to C will I your parents. For multiple inheritance you must provide all the parents at once, C. @@ -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 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's exports but also +those from type libraries and other modules is to use +L or L. + =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 + +If you override C 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 method, which will be +called from the inlined constructor. + +Alternately, if you really need to provide a different C, 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 Eautarch@urth.orgE