4 use Test::More tests=>10;
7 use_ok 'Moose::Util::TypeConstraints';
8 use_ok 'MooseX::Meta::TypeConstraint::Structured::Structurable';
9 use_ok 'MooseX::Meta::TypeConstraint::Structured::Positional';
10 use_ok 'MooseX::Meta::TypeConstraint::Structured::Named';
13 my $tuple = MooseX::Meta::TypeConstraint::Structured::Structurable->new(
15 structured_type => 'MooseX::Meta::TypeConstraint::Structured::Positional',
16 package_defined_in => __PACKAGE__,
17 parent => find_type_constraint('ArrayRef'),
20 Moose::Util::TypeConstraints::register_type_constraint($tuple);
22 ## Make sure the new type constraints have been registered
24 ok Moose::Util::TypeConstraints::find_type_constraint('Tuple')
25 => 'Found the Tuple Type';
28 package Test::MooseX::Types::Structured::Positionable;
31 use Moose::Util::TypeConstraints;
33 has 'tuple' => (is=>'rw', isa=>'Tuple[Int,Str,Int]');
37 ok my $positioned_obj = Test::MooseX::Types::Structured::Positionable->new,
38 => 'Got a good object';
40 ok $positioned_obj->tuple([1,'hello',3])
41 => "[1,'hello',3] properly suceeds";
44 $positioned_obj->tuple([1,2,'world']);
45 }, qr/Validation failed for 'Int' failed with value world/ => "[1,2,'world'] properly fails";
48 $positioned_obj->tuple(['hello1',2,3]);
49 }, qr/Validation failed for 'Int' failed with value hello1/ => "['hello',2,3] properly fails";
52 $positioned_obj->tuple(['hello2',2,'world']);
53 }, qr/Validation failed for 'Int' failed with value hello2/ => "['hello',2,'world'] properly fails";
58 #ok Moose::Util::TypeConstraints::_detect_parameterized_type_constraint('HashRef[key1 => Int, key2=>Int, key3=>ArrayRef[Int]]')
59 # => 'detected correctly';
62 # [Moose::Util::TypeConstraints::_parse_parameterized_type_constraint('HashRef[key1 => Int, key2=>Int, key3=>ArrayRef[Int]]')],
63 # ["HashRef", "key1", "Int", "key2", "Int", "key3", "ArrayRef[Int]"]
64 # => 'Correctly parsed HashRef[key1 => Int, key2=>Int, key3=>ArrayRef[Int]]';