Lots of fixes to object destruction.
[gitmo/Moose.git] / lib / Moose / Manual / Types.pod
index 7b623d1..391083c 100644 (file)
@@ -69,7 +69,7 @@ can even do something like C<HashRef[ArrayRef[Str]]>.
 The C<Maybe[`a]> type deserves a special mention. Used by itself, it
 doesn't really mean anything (and is equivalent to C<Item>). When it
 is parameterized, it means that the value is either C<undef> or the
-parameterized type. So C<Maybe[Int]> means an integer or C<undef>
+parameterized type. So C<Maybe[Int]> means an integer or C<undef>.
 
 For more details on the type hierarchy, see
 L<Moose::Util::TypeConstraints>.
@@ -183,6 +183,21 @@ recommend that you centralize all of these definitions in a single
 package, C<MyApp::Types>, which can be loaded by other classes in your
 application.
 
+Once you're doing this, you should almost certainly look at the
+L<MooseX::Types> extension which allows easy declaration of type libraries
+and can export your types as perl constants so that you can refer to them
+as just
+
+  has 'counter' => (is => 'rw', isa => PositiveInt);
+
+rather than needing to fully qualify them everywhere. It also allows
+
+  has 'counts' => (is => 'ro', isa => HashRef[PositiveInt]);
+
+and similarly for the union and other syntax discussed below, which
+will compile time check your use of names and is generally more robust
+than the string type parsing for complex cases.
+
 =head1 COERCION
 
 One of the most powerful features of Moose's type system is its
@@ -349,7 +364,7 @@ type, or as the value for an attribute's C<isa> option:
 
   has 'size' => (
       is => 'ro',
-      isa => subtype 'Int' => where { $_ > 0 },
+      isa => subtype('Int' => where { $_ > 0 }),
   );
 
 This is handy when you want to create a one-off type and don't want to
@@ -403,7 +418,7 @@ C<find_type_constraint> function exported by
 L<Moose::Util::TypeConstraints>:
 
   class_type('MyApp::User')
-      unless find_type_constraint('MyApp::User') || ;
+      unless find_type_constraint('MyApp::User');
 
 This sort of "find or create" logic is simple to write, and will let
 you work around load order issues.