8 use Scalar::Util qw(refaddr);
11 use_ok('Moose::Util::TypeConstraints');
14 # subtype 'aliasing' ...
17 subtype 'Numb3rs' => as 'Num';
18 } '... create bare subtype fine';
20 my $numb3rs = find_type_constraint('Numb3rs');
21 isa_ok($numb3rs, 'Moose::Meta::TypeConstraint');
26 package Test::Moose::Meta::TypeConstraint::Union;
28 use overload '""' => sub {'Broken|Test'}, fallback => 1;
31 extends 'Moose::Meta::TypeConstraint';
34 my $dummy_instance = Test::Moose::Meta::TypeConstraint::Union->new;
36 ok $dummy_instance => "Created Instance";
38 isa_ok $dummy_instance,
39 'Test::Moose::Meta::TypeConstraint::Union' => 'isa correct type';
41 is "$dummy_instance", "Broken|Test" =>
42 'Got expected stringification result';
44 my $subtype1 = subtype 'New1' => as $dummy_instance;
46 ok $subtype1 => 'made a subtype from our type object';
48 my $subtype2 = subtype 'New2' => as $subtype1;
50 ok $subtype2 => 'made a subtype of our subtype';
55 my $type = find_type_constraint('Num');
57 my $ok_1 = eval { $type->assert_valid(1); };
58 ok($ok_1, "we can assert_valid that 1 is of type $type");
60 my $ok_2 = eval { $type->assert_valid('foo'); };
62 ok(! $ok_2, "'foo' is not of type $type");
65 qr{validation failed for .\Q$type\E.}i,
66 "correct error thrown"
71 for my $t (qw(Bar Foo)) {
72 my $tc = Moose::Meta::TypeConstraint->new({
76 Moose::Util::TypeConstraints::register_type_constraint($tc);
79 my $foo = Moose::Util::TypeConstraints::find_type_constraint('Foo');
80 my $bar = Moose::Util::TypeConstraints::find_type_constraint('Bar');
82 ok(!$foo->equals($bar), "Foo type is not equal to Bar type");
83 ok( $foo->equals($foo), "Foo equals Foo");
84 ok( 0+$foo == refaddr($foo), "overloading works");