[Moose-commits] r7629 - Moose/trunk/lib/Moose/Cookbook/Extending

autarch at code2.0beta.co.uk autarch at code2.0beta.co.uk
Thu Feb 12 16:49:20 GMT 2009


Author: autarch
Date: 2009-02-12 08:49:20 -0800 (Thu, 12 Feb 2009)
New Revision: 7629

Modified:
   Moose/trunk/lib/Moose/Cookbook/Extending/Recipe2.pod
Log:
Revised recipe 2


Modified: Moose/trunk/lib/Moose/Cookbook/Extending/Recipe2.pod
===================================================================
--- Moose/trunk/lib/Moose/Cookbook/Extending/Recipe2.pod	2009-02-12 16:37:27 UTC (rev 7628)
+++ Moose/trunk/lib/Moose/Cookbook/Extending/Recipe2.pod	2009-02-12 16:49:20 UTC (rev 7629)
@@ -17,7 +17,7 @@
   use Moose::Util::MetaRole;
   use MooseX::Debugging::Role::Object;
 
-  Moose::Exporter->setup_import_methods();
+  Moose::Exporter->setup_import_methods;
 
   sub init_meta {
       shift;
@@ -53,6 +53,29 @@
 MooseX::Debugging>", it automatically gets the debugging role applied
 to its base object class.
 
+There are a few pieces of code worth looking at more closely.
+
+  Moose::Exporter->setup_import_methods;
+
+This creates an C<import> method in the C<MooseX::Debugging>
+package. Since we are not actually exporting anything, we do not pass
+C<setup_import_methods> any parameters. However, we need to have an
+C<import> method to ensure that our C<init_meta> method is called.
+
+Then in our C<init_meta> method we have this line:
+
+      Moose->init_meta(%options);
+
+This is a bit of boilerplate that almost every extension will
+use. This ensures that the caller has a normal Moose metaclass
+I<before> we go and add traits to it.
+
+The C<< Moose->init_meta >> method does ensures that the caller has a
+sane metaclass, and we don't want to replicate that logic in our
+extension. If the C<< Moose->init_meta >> was already called (because
+the caller did C<use Moose> before using our extension), then calling
+C<< Moose->init_meta >> again is effectively a no-op.
+
 =head1 AUTHOR
 
 Dave Rolsky E<lt>autarch at urth.orgE<gt>




More information about the Moose-commits mailing list