because Structurable is not a word
[gitmo/MooseX-Types-Structured.git] / lib / MooseX / Meta / TypeConstraint / Structured / Generator.pm
diff --git a/lib/MooseX/Meta/TypeConstraint/Structured/Generator.pm b/lib/MooseX/Meta/TypeConstraint/Structured/Generator.pm
new file mode 100755 (executable)
index 0000000..8f9906c
--- /dev/null
@@ -0,0 +1,33 @@
+package MooseX::Meta::TypeConstraint::Structured::Generator;
+
+use strict;
+use warnings;
+
+use metaclass;
+
+use base 'Moose::Meta::TypeConstraint';
+use Moose::Util::TypeConstraints ();
+
+__PACKAGE__->meta->add_attribute('structured_type' => (
+    accessor  => 'structured_type',
+    predicate => 'has_structured_type',
+));
+
+sub parse_parameter_str {
+       my ($self, $type_str) = @_;
+       return $self->structured_type->parse_parameter_str($type_str);
+}
+
+sub parameterize {
+       my ($self, @contained_tcs) = @_;
+       my $tc_name = $self->name .'['. join(',', map {$_->name} @contained_tcs) .']';
+       
+       return $self->structured_type->new(
+               name => $tc_name,
+               parent => $self->parent,
+               package_defined_in => __PACKAGE__,
+               signature => \@contained_tcs,
+       );                      
+}
+
+1;