9 traits => [ qw(MooseX::UndefTolerant::Attribute)],
12 predicate => 'has_attr1',
18 predicate => 'has_attr2',
25 use MooseX::UndefTolerant;
30 predicate => 'has_attr1',
35 predicate => 'has_attr2',
43 note 'Testing class with a single UndefTolerant attribute';
46 ok(!$obj->has_attr1, 'attr1 has no value before it is assigned');
47 ok(!$obj->has_attr2, 'attr2 has no value before it is assigned');
51 my $obj = Foo->new(attr1 => undef);
52 ok(!$obj->has_attr1, 'UT attr1 has no value when assigned undef in constructor');
53 ok (exception { $obj = Foo->new(attr2 => undef) },
54 'But assigning undef to attr2 generates a type constraint error');
58 my $obj = Foo->new(attr1 => 1234, attr2 => 5678);
59 is($obj->attr1, 1234, 'assigning a defined value during construction works as normal');
60 ok($obj->has_attr1, '...and the predicate returns true as normal');
61 is($obj->attr2, 5678, 'assigning a defined value during construction works as normal');
62 ok($obj->has_attr2, '...and the predicate returns true as normal');
67 note 'Testing class with the entire class being UndefTolerant';
70 ok(!$obj->has_attr1, 'attr1 has no value before it is assigned');
74 my $obj = Bar->new(attr1 => undef);
75 ok(!$obj->has_attr1, 'attr1 has no value when assigned undef in constructor');
76 ok (!exception { $obj = Bar->new(attr2 => undef) },
77 'assigning undef to attr2 does not produce an error');
78 ok(!$obj->has_attr2, 'attr2 has no value when assigned undef in constructor');
82 my $obj = Bar->new(attr1 => 1234);
83 is($obj->attr1, 1234, 'assigning a defined value during construction works as normal');
84 ok($obj->has_attr1, '...and the predicate returns true as normal');
89 note 'Constructor behaviour: mutable classes';
94 note 'Constructor behaviour: immutable classes';
96 Foo->meta->make_immutable;
97 Bar->meta->make_immutable;
99 local $TODO = 'some immutable cases are not handled yet';
100 # for now, catch errors
101 ok(! exception { do_tests }, 'tests do not die');
103 is(Test::More->builder->current_test, 28, 'if we got here, we can declare victory!');