8 use Scalar::Util qw(refaddr);
10 use Moose::Util::TypeConstraints;
12 # subtype 'aliasing' ...
15 subtype 'Numb3rs' => as 'Num';
16 }, undef, '... create bare subtype fine' );
18 my $numb3rs = find_type_constraint('Numb3rs');
19 isa_ok($numb3rs, 'Moose::Meta::TypeConstraint');
24 package Test::Moose::Meta::TypeConstraint::Union;
26 use overload '""' => sub {'Broken|Test'}, fallback => 1;
29 extends 'Moose::Meta::TypeConstraint';
32 my $dummy_instance = Test::Moose::Meta::TypeConstraint::Union->new;
34 ok $dummy_instance => "Created Instance";
36 isa_ok $dummy_instance,
37 'Test::Moose::Meta::TypeConstraint::Union' => 'isa correct type';
39 is "$dummy_instance", "Broken|Test" =>
40 'Got expected stringification result';
42 my $subtype1 = subtype 'New1' => as $dummy_instance;
44 ok $subtype1 => 'made a subtype from our type object';
46 my $subtype2 = subtype 'New2' => as $subtype1;
48 ok $subtype2 => 'made a subtype of our subtype';
53 my $type = find_type_constraint('Num');
55 my $ok_1 = eval { $type->assert_valid(1); };
56 ok($ok_1, "we can assert_valid that 1 is of type $type");
58 my $ok_2 = eval { $type->assert_valid('foo'); };
60 ok(! $ok_2, "'foo' is not of type $type");
63 qr{validation failed for .\Q$type\E.}i,
64 "correct error thrown"
69 for my $t (qw(Bar Foo)) {
70 my $tc = Moose::Meta::TypeConstraint->new({
74 Moose::Util::TypeConstraints::register_type_constraint($tc);
77 my $foo = Moose::Util::TypeConstraints::find_type_constraint('Foo');
78 my $bar = Moose::Util::TypeConstraints::find_type_constraint('Bar');
80 ok(!$foo->equals($bar), "Foo type is not equal to Bar type");
81 ok( $foo->equals($foo), "Foo equals Foo");
82 ok( 0+$foo == refaddr($foo), "overloading works");
85 ok $subtype1, "type constraint boolean overload works";