8f9906c7654177641a912ce59ee1c90b5a51df77
[gitmo/MooseX-Types-Structured.git] / lib / MooseX / Meta / TypeConstraint / Structured / Generator.pm
1 package MooseX::Meta::TypeConstraint::Structured::Generator;
2
3 use strict;
4 use warnings;
5
6 use metaclass;
7
8 use base 'Moose::Meta::TypeConstraint';
9 use Moose::Util::TypeConstraints ();
10
11 __PACKAGE__->meta->add_attribute('structured_type' => (
12     accessor  => 'structured_type',
13     predicate => 'has_structured_type',
14 ));
15
16 sub parse_parameter_str {
17         my ($self, $type_str) = @_;
18         return $self->structured_type->parse_parameter_str($type_str);
19 }
20
21 sub parameterize {
22         my ($self, @contained_tcs) = @_;
23         my $tc_name = $self->name .'['. join(',', map {$_->name} @contained_tcs) .']';
24         
25         return $self->structured_type->new(
26                 name => $tc_name,
27                 parent => $self->parent,
28                 package_defined_in => __PACKAGE__,
29                 signature => \@contained_tcs,
30         );                      
31 }
32
33 1;