4 use Test::More tests=>9;
9 package Test::MooseX::Meta::TypeConstraint::Structured::Combined;
12 use MooseX::Types::Structured qw(Dict Tuple);
13 use MooseX::Types::Moose qw(Int Str Object ArrayRef HashRef Maybe);
15 has 'dict_with_tuple' => (is=>'rw', isa=>Dict[key1=>Str, key2=>Tuple[Int,Str]]);
16 has 'dict_with_tuple_with_union' => (is=>'rw', isa=>Dict[key1=>Str|Object, key2=>Tuple[Int,Str|Object]] );
19 ## Instantiate a new test object
21 ok my $record = Test::MooseX::Meta::TypeConstraint::Structured::Combined->new
22 => 'Instantiated new Record test class.';
24 isa_ok $record => 'Test::MooseX::Meta::TypeConstraint::Structured::Combined'
25 => 'Created correct object type.';
27 ## Test dict_with_tuple
30 $record->dict_with_tuple({key1=>'Hello', key2=>[1,'World']});
31 } => 'Set tuple attribute without error';
34 $record->dict_with_tuple({key1=>'Hello', key2=>['World',2]});
35 }, qr/Attribute \(dict_with_tuple\) does not pass the type constraint/
36 => 'Threw error on bad constraint';
38 ## Test dict_with_tuple_with_union: Dict[key1=>'Str|Object', key2=>Tuple['Int','Str|Object']]
41 $record->dict_with_tuple_with_union({key1=>'Hello', key2=>[1,'World']});
42 } => 'Set tuple attribute without error';
45 $record->dict_with_tuple_with_union({key1=>'Hello', key2=>['World',2]});
46 }, qr/Attribute \(dict_with_tuple_with_union\) does not pass the type constraint/
47 => 'Threw error on bad constraint';
50 $record->dict_with_tuple_with_union({key1=>$record, key2=>[1,'World']});
51 } => 'Set tuple attribute without error';
54 $record->dict_with_tuple_with_union({key1=>'Hello', key2=>[1,$record]});
55 } => 'Set tuple attribute without error';
58 $record->dict_with_tuple_with_union({key1=>1, key2=>['World',2]});
59 }, qr/Attribute \(dict_with_tuple_with_union\) does not pass the type constraint/
60 => 'Threw error on bad constraint';