4 use Test::More tests=>3;
8 ## Copied from Moose::Util::TypeConstraints
12 my $valid_chars = qr{[\w:]};
13 my $type_atom = qr{ $valid_chars+ };
15 my $type = qr{ $valid_chars+ (?: \[ (??{$any}) \] )? }x;
16 my $type_capture_parts = qr{ ($valid_chars+) (?: \[ ((??{$any})) \] )? }x;
17 my $type_with_parameter = qr{ $valid_chars+ \[ (??{$any}) \] }x;
19 my $op_union = qr{ \s* \| \s* }x;
20 my $union = qr{ $type (?: $op_union $type )+ }x;
22 ## New Stuff for structured types.
24 my $indirection = qr{=>};
25 my $divider_tokens = qr{ $comma | $indirection }x;
26 my $structure_divider = qr{\s* $divider_tokens \s*}x;
27 my $structure_elements = qr{ ($type $structure_divider*)+ }x;
29 $any = qr{ $type | $union | $structure_elements }x;
31 ## New Proposed methods to parse and create
32 sub _parse_structured_type_constraint {
33 { no warnings 'void'; $any; } # force capture of interpolated lexical
35 my($base, $elements) = ($_[0] =~ m{ $type_capture_parts }x);
36 return ($base, [split($structure_divider, $elements)]);
40 [_parse_structured_type_constraint('ArrayRef[Int,Str]')],
41 ["ArrayRef", ["Int", "Str"]]
42 => 'Correctly parsed ArrayRef[Int,Str]';
45 [_parse_structured_type_constraint('ArrayRef[ArrayRef[Int],Str]')],
46 ["ArrayRef", ["ArrayRef[Int]", "Str"]]
47 => 'Correctly parsed ArrayRef[ArrayRef[Int],Str]';
50 [_parse_structured_type_constraint('HashRef[key1 => Int, key2=>Int, key3=>ArrayRef[Int]]')],
51 ["HashRef", ["key1", "Int", "key2", "Int", "key3", "ArrayRef[Int]"]]
52 => 'Correctly parsed HashRef[key1 => Int, key2=>Int, key3=>ArrayRef[Int]]';