fixing the authors lists and adding the ClassName type constraint
[gitmo/Moose.git] / lib / Moose / Util / TypeConstraints.pm
index 2ac9d5a..9dfa98b 100644 (file)
@@ -12,6 +12,26 @@ use Sub::Exporter;
 our $VERSION   = '0.12';
 our $AUTHORITY = 'cpan:STEVAN';
 
+# Prototyped subs must be predeclared because we have a circular dependency
+# with Moose::Meta::Attribute et. al. so in case of us being use'd first the
+# predeclaration ensures the prototypes are in scope when consumers are
+# compiled
+
+sub find_type_constraint ($);
+sub _create_type_constraint ($$$;$$);
+sub _install_type_coercions ($$);
+sub create_type_constraint_union (@);
+sub type ($$;$$);
+sub subtype ($$;$$$);
+sub coerce ($@);
+sub as      ($);
+sub from    ($);
+sub where   (&);
+sub via     (&);
+sub message     (&);
+sub optimize_as (&);
+sub enum ($;@);
+
 use Moose::Meta::TypeConstraint;
 use Moose::Meta::TypeCoercion;
 
@@ -225,6 +245,11 @@ subtype 'Role'
     => as 'Object' 
     => where { $_->can('does') }
     => optimize_as { blessed($_[0]) && $_[0]->can('does') };
+    
+subtype 'ClassName' 
+    => as 'Str' 
+    => where { eval { $_->isa('UNIVERSAL') } }
+    => optimize_as { !ref($_[0]) && eval { $_[0]->isa('UNIVERSAL') } };    
 
 {
     my @BUILTINS = list_all_type_constraints();
@@ -314,6 +339,7 @@ could probably use some work, but it works for me at the moment.
               Num
                 Int
               Str
+                ClassName
           Ref
               ScalarRef
               ArrayRef
@@ -330,6 +356,12 @@ Suggestions for improvement are welcome.
 B<NOTE:> The C<Undef> type constraint does not work correctly 
 in every occasion, please use it sparringly.
 
+B<NOTE:> The C<ClassName> type constraint is simply a subtype 
+of string which responds true to C<isa('UNIVERSAL')>. This means
+that your class B<must> be loaded for this type constraint to 
+pass. I know this is not ideal for all, but it is a saner 
+restriction then most others. 
+
 =head2 Use with Other Constraint Modules
 
 This module should play fairly nicely with other constraint