rename postionalable to a more generic name
[gitmo/MooseX-Types-Structured.git] / lib / MooseX / Meta / TypeConstraint / Structured / Structurable.pm
CommitLineData
bfef1b30 1package MooseX::Meta::TypeConstraint::Structured::Positionable;
2
3use strict;
4use warnings;
5
6use metaclass;
7
66c84636 8use base 'Moose::Meta::TypeConstraint';
bfef1b30 9use Moose::Util::TypeConstraints ();
10use MooseX::Meta::TypeConstraint::Structured::Positional;
11
66c84636 12__PACKAGE__->meta->add_attribute('structured_type' => (
13 accessor => 'structured_type',
14 predicate => 'has_structured_type',
15));
16
011bacc6 17 my $comma = qr{,};
18 my $indirection = qr{=>};
19 my $divider_ops = qr{ $comma | $indirection }x;
20 my $structure_divider = qr{\s* $divider_ops \s*}x;
bfef1b30 21
22sub parse_parameter_str {
011bacc6 23 my ($self, $type_str) = @_;
24 my @type_strs = split($structure_divider, $type_str);
bfef1b30 25 return map {Moose::Util::TypeConstraints::find_or_create_isa_type_constraint($_)} @type_strs;
26}
27
28sub parameterize {
011bacc6 29 my ($self, @contained_tcs) = @_;
30 my $tc_name = $self->name .'['. join(',', map {$_->name} @contained_tcs) .']';
bfef1b30 31
32 return MooseX::Meta::TypeConstraint::Structured::Positional->new(
33 name => $tc_name,
011bacc6 34 parent => Moose::Util::TypeConstraints::find_type_constraint('ArrayRef'),
bfef1b30 35 package_defined_in => __PACKAGE__,
36 signature => \@contained_tcs,
37 );
bfef1b30 38}
39
40
411;