6 use Test::More tests => 12;
10 use_ok('Moose::Util::TypeConstraints');
13 # testing the parameterize method
16 my $parameterizable = subtype 'parameterizable_hashref',
19 my $parameterized = subtype 'parameterized_hashref',
22 my $int = Moose::Util::TypeConstraints::find_type_constraint('Int');
24 my $from_parameterizable = $parameterizable->parameterize($int);
26 isa_ok $parameterizable, 'Moose::Meta::TypeConstraint::Parameterizable',
27 => 'Got expected type instance';
29 package Test::Moose::Meta::TypeConstraint::Parameterizable;
32 has parameterizable => (is=>'rw', isa=>$parameterizable);
33 has parameterized => (is=>'rw', isa=>$parameterized);
34 has from_parameterizable => (is=>'rw', isa=>$from_parameterizable);
37 # Create and check a dummy object
39 ok my $params = Test::Moose::Meta::TypeConstraint::Parameterizable->new()
40 => 'Create Dummy object for testing';
42 isa_ok $params, 'Test::Moose::Meta::TypeConstraint::Parameterizable'
43 => 'isa correct type';
45 # test parameterizable
48 $params->parameterizable({a=>'Hello', b=>'World'});
49 } => 'No problem setting parameterizable';
51 is_deeply $params->parameterizable, {a=>'Hello', b=>'World'}
52 => 'Got expected values';
57 $params->parameterized({a=>1, b=>2});
58 } => 'No problem setting parameterized';
60 is_deeply $params->parameterized, {a=>1, b=>2}
61 => 'Got expected values';
64 $params->parameterized({a=>'Hello', b=>'World'});
65 }, qr/Attribute \(parameterized\) does not pass the type constraint/
66 => 'parameterized throws expected error';
68 # test from_parameterizable
71 $params->from_parameterizable({a=>1, b=>2});
72 } => 'No problem setting from_parameterizable';
74 is_deeply $params->from_parameterizable, {a=>1, b=>2}
75 => 'Got expected values';
78 $params->from_parameterizable({a=>'Hello', b=>'World'});
79 }, qr/Attribute \(from_parameterizable\) does not pass the type constraint/
80 => 'from_parameterizable throws expected error';