Implement a class_type generator
[gitmo/Mouse.git] / lib / Mouse / PurePerl.pm
index b601b29..f2802db 100644 (file)
@@ -77,9 +77,23 @@ sub get_code_ref{
 package
     Mouse::Util::TypeConstraints;
 
+sub _generate_class_type_for{
+    my($for_class, $name) = @_;
+
+    my $predicate = sub{ Scalar::Util::blessd($_[0]) && $_[0]->isa($for_class) };
+
+    if(defined $name){
+        no strict 'refs';
+        *{ caller() . '::' . $name } = $predicate;
+        return;
+    }
+
+    return $predicate;
+}
+
+
 sub Any        { 1 }
 sub Item       { 1 }
-sub Maybe      { 1 }
 
 sub Bool       { $_[0] ? $_[0] eq '1' : 1 }
 sub Undef      { !defined($_[0]) }
@@ -168,6 +182,8 @@ sub builder              { $_[0]->{builder}                }
 sub should_auto_deref    { $_[0]->{auto_deref}             }
 sub should_coerce        { $_[0]->{coerce}                 }
 
+sub documentation        { $_[0]->{documentation}          }
+
 # predicates
 
 sub has_accessor         { exists $_[0]->{accessor}        }
@@ -182,6 +198,10 @@ sub has_type_constraint  { exists $_[0]->{type_constraint} }
 sub has_trigger          { exists $_[0]->{trigger}         }
 sub has_builder          { exists $_[0]->{builder}         }
 
+sub has_documentation    { exists $_[0]->{documentation}   }
+
+sub accessor_metaclass(){ 'Mouse::Meta::Method::Accessor' }
+
 package
     Mouse::Meta::TypeConstraint;
 
@@ -191,10 +211,10 @@ sub message { $_[0]->{message} }
 
 sub _compiled_type_constraint{ $_[0]->{compiled_type_constraint} }
 
-sub has_coercion{ exists $_[0]->{_compiled_type_coercion} }
+sub _compiled_type_coercion  { $_[0]->{_compiled_type_coercion}  }
 
-package
-    Mouse::Meta::Method::Accessor;
+
+sub has_coercion{ exists $_[0]->{_compiled_type_coercion} }
 
 1;
 __END__