From: Dave Rolsky Date: Thu, 12 Feb 2009 16:49:20 +0000 (+0000) Subject: Revised recipe 2 X-Git-Tag: 0.69~13 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=871cda31abd5e6d7af65c9d84e0bfbd5822d00e9;p=gitmo%2FMoose.git Revised recipe 2 --- diff --git a/lib/Moose/Cookbook/Extending/Recipe2.pod b/lib/Moose/Cookbook/Extending/Recipe2.pod index 62bd71b..85bc5d9 100644 --- a/lib/Moose/Cookbook/Extending/Recipe2.pod +++ b/lib/Moose/Cookbook/Extending/Recipe2.pod @@ -17,7 +17,7 @@ Moose::Cookbook::Extending::Recipe2 - Providing a role for the base object class 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 @@ L, we ensure that when a module does "S", 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 method in the C +package. Since we are not actually exporting anything, we do not pass +C any parameters. However, we need to have an +C method to ensure that our C method is called. + +Then in our C 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 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 before using our extension), then calling +C<< Moose->init_meta >> again is effectively a no-op. + =head1 AUTHOR Dave Rolsky Eautarch@urth.orgE