[Moose-commits] r7419 - Moose/branches/moose-manual/lib/Moose/Manual

autarch at code2.0beta.co.uk autarch at code2.0beta.co.uk
Thu Jan 29 18:20:10 GMT 2009


Author: autarch
Date: 2009-01-29 10:20:10 -0800 (Thu, 29 Jan 2009)
New Revision: 7419

Modified:
   Moose/branches/moose-manual/lib/Moose/Manual/Types.pod
Log:
Add a mention of load order issues


Modified: Moose/branches/moose-manual/lib/Moose/Manual/Types.pod
===================================================================
--- Moose/branches/moose-manual/lib/Moose/Manual/Types.pod	2009-01-29 18:10:03 UTC (rev 7418)
+++ Moose/branches/moose-manual/lib/Moose/Manual/Types.pod	2009-01-29 18:20:10 UTC (rev 7419)
@@ -396,6 +396,25 @@
       $self->say("Good morning ${name}!");
   }
 
+=head1 LOAD ORDER ISSUES
+
+Because Moose types are defined at runtime, you can sometimes run into
+issues with load order. In particular, you may sometimes want to use a
+class's type constraint before it exists.
+
+We recommend several things. First, define I<all> of your custom types
+in one module, C<MyApp::Types>. Second, load this module in all of
+your other modules.
+
+If you are still having load order problems, you can make use of the
+C<find_type_constraint> function exported by
+L<Moose::Util::TypeConstraints>:
+
+  my $type = find_type_constraint('MyApp::User') || class_type('MyApp::User');
+
+This sort of "find or create" logic is simple to write, and will let
+you work around load order issues.
+
 =head1 AUTHOR
 
 Dave Rolsky E<lt>autarch at urth.orgE<gt>




More information about the Moose-commits mailing list