6 use Test::More tests => 19;
10 use_ok('Moose::Util::TypeConstraints');
13 # subtype 'aliasing' ...
16 subtype 'Numb3rs' => as 'Num';
17 } '... create bare subtype fine';
19 my $numb3rs = find_type_constraint('Numb3rs');
20 isa_ok($numb3rs, 'Moose::Meta::TypeConstraint');
25 package Test::Moose::Meta::TypeConstraint::Union;
27 use overload '""' => sub {'Broken|Test'}, fallback => 1;
30 extends 'Moose::Meta::TypeConstraint';
33 my $dummy_instance = Test::Moose::Meta::TypeConstraint::Union->new;
35 ok $dummy_instance => "Created Instance";
37 isa_ok $dummy_instance,
38 'Test::Moose::Meta::TypeConstraint::Union' => 'isa correct type';
40 is "$dummy_instance", "Broken|Test" =>
41 'Got expected stringification result';
43 my $subtype1 = subtype 'New1' => as $dummy_instance;
45 ok $subtype1 => 'made a subtype from our type object';
47 my $subtype2 = subtype 'New2' => as $subtype1;
49 ok $subtype2 => 'made a subtype of our subtype';
51 # testing the parameterize method
54 my $parameterizable = subtype 'parameterizable_hashref',
57 my $parameterized = subtype 'parameterized_hashref',
60 my $int = Moose::Util::TypeConstraints::find_type_constraint('Int');
62 my $from_parameterizable = $parameterizable->parameterize($int);
64 isa_ok $parameterizable, 'Moose::Meta::TypeConstraint::Parameterizable',
65 => 'Got expected type instance';
67 package Test::Moose::Meta::TypeConstraint::Parameterizable;
70 has parameterizable => (is=>'rw', isa=>$parameterizable);
71 has parameterized => (is=>'rw', isa=>$parameterized);
72 has from_parameterizable => (is=>'rw', isa=>$from_parameterizable);
75 # Create and check a dummy object
77 ok my $params = Test::Moose::Meta::TypeConstraint::Parameterizable->new()
78 => 'Create Dummy object for testing';
80 isa_ok $params, 'Test::Moose::Meta::TypeConstraint::Parameterizable'
81 => 'isa correct type';
83 # test parameterizable
86 $params->parameterizable({a=>'Hello', b=>'World'});
87 } => 'No problem setting parameterizable';
89 is_deeply $params->parameterizable, {a=>'Hello', b=>'World'}
90 => 'Got expected values';
95 $params->parameterized({a=>1, b=>2});
96 } => 'No problem setting parameterized';
98 is_deeply $params->parameterized, {a=>1, b=>2}
99 => 'Got expected values';
102 $params->parameterized({a=>'Hello', b=>'World'});
103 }, qr/Attribute \(parameterized\) does not pass the type constraint/
104 => 'parameterized throws expected error';
106 # test from_parameterizable
109 $params->from_parameterizable({a=>1, b=>2});
110 } => 'No problem setting from_parameterizable';
112 is_deeply $params->from_parameterizable, {a=>1, b=>2}
113 => 'Got expected values';
116 $params->from_parameterizable({a=>'Hello', b=>'World'});
117 }, qr/Attribute \(from_parameterizable\) does not pass the type constraint/
118 => 'from_parameterizable throws expected error';