finished parameterized method, tests and converted Moose::Util::TypeConstraints to...
[gitmo/Moose.git] / lib / Moose / Meta / TypeConstraint / Parameterizable.pm
index 95193eb..a8e32a3 100644 (file)
@@ -9,6 +9,7 @@ $VERSION = eval $VERSION;
 our $AUTHORITY = 'cpan:STEVAN';
 
 use base 'Moose::Meta::TypeConstraint';
+use Moose::Meta::TypeConstraint::Parameterized;
 
 __PACKAGE__->meta->add_attribute('constraint_generator' => (
     accessor  => 'constraint_generator',
@@ -40,6 +41,29 @@ sub _can_coerce_constraint_from {
     };
 }
 
+sub parameterize {
+       my ($self, @args) = @_;
+    
+    ## ugly hacking to deal with tc naming normalization issue
+    my ($tc_name, $contained_tc);
+    if (ref $args[0]) {
+        $contained_tc = shift @args;
+        $tc_name = $self->name .'['. $contained_tc->name .']';
+    } else {
+        ($tc_name, $contained_tc) = @args;
+    }
+       
+       unless($contained_tc->isa('Moose::Meta::TypeConstraint')) {
+               Moose->throw_error("The type parameter must be a Moose meta type");
+       }
+       
+    return Moose::Meta::TypeConstraint::Parameterized->new(
+        name           => $tc_name,
+        parent         => $self,
+        type_parameter => $contained_tc,
+    ); 
+}
+
 
 1;
 
@@ -62,6 +86,10 @@ Moose::Meta::TypeConstraint::Parameterizable - Higher Order type constraints for
 
 =item B<generate_constraint_for>
 
+=item B<parameterize>
+
+Given an array of type constraints, parameterize the current type constraint.
+
 =item B<meta>
 
 =back