Commit | Line | Data |
bfef1b30 |
1 | package MooseX::Meta::TypeConstraint::Structured::Positionable; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use metaclass; |
7 | |
66c84636 |
8 | use base 'Moose::Meta::TypeConstraint'; |
bfef1b30 |
9 | use Moose::Util::TypeConstraints (); |
10 | use 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 | |
22 | sub 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 | |
28 | sub 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 | |
41 | 1; |