back to a regular and registered Tuple that covers most of the requirements
[gitmo/MooseX-Types-Structured.git] / lib / MooseX / Meta / TypeConstraint / Structured / Positionable.pm
1 package MooseX::Meta::TypeConstraint::Structured::Positionable;
2
3 use strict;
4 use warnings;
5
6 use metaclass;
7
8 use base 'Moose::Meta::TypeConstraint::Parameterizable';
9 use Moose::Util::TypeConstraints ();
10 use MooseX::Meta::TypeConstraint::Structured::Positional;
11
12     my $comma = qr{,};
13     my $indirection = qr{=>};
14     my $divider_ops = qr{ $comma | $indirection }x;
15     my $structure_divider = qr{\s* $divider_ops \s*}x;
16
17 sub parse_parameter_str {
18     my ($self, $type_str) = @_;
19         my @type_strs = split($structure_divider, $type_str);
20     return map {Moose::Util::TypeConstraints::find_or_create_isa_type_constraint($_)} @type_strs;
21 }
22
23 sub parameterize {
24         my ($self, @contained_tcs) = @_;
25         my $tc_name = $self->name .'['. join(',', map {$_->name} @contained_tcs) .']';
26         
27         return MooseX::Meta::TypeConstraint::Structured::Positional->new(
28                 name => $tc_name,
29                 parent => Moose::Util::TypeConstraints::find_type_constraint('ArrayRef'),
30                 package_defined_in => __PACKAGE__,
31                 signature => \@contained_tcs,
32         );                      
33 }
34
35
36 1;