1 use Test::More tests => 14;
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',
41 note 'Constructor behaviour';
44 note 'Testing class with a single UndefTolerant attribute';
47 ok(!$obj->has_attr1, 'attr1 has no value before it is assigned');
48 ok(!$obj->has_attr2, 'attr2 has no value before it is assigned');
52 my $obj = Foo->new(attr1 => undef);
53 ok(!$obj->has_attr1, 'UT attr1 has no value when assigned undef in constructor');
54 ok (exception { $obj = Foo->new(attr2 => undef) },
55 'But assigning undef to attr2 generates a type constraint error');
59 my $obj = Foo->new(attr1 => 1234, attr2 => 5678);
60 is($obj->attr1, 1234, 'assigning a defined value during construction works as normal');
61 ok($obj->has_attr1, '...and the predicate returns true as normal');
62 is($obj->attr2, 5678, 'assigning a defined value during construction works as normal');
63 ok($obj->has_attr2, '...and the predicate returns true as normal');
68 note 'Testing class with the entire class being UndefTolerant';
71 ok(!$obj->has_attr1, 'attr1 has no value before it is assigned');
75 my $obj = Bar->new(attr1 => undef);
76 ok(!$obj->has_attr1, 'attr1 has no value when assigned undef in constructor');
77 ok (!exception { $obj = Bar->new(attr2 => undef) },
78 'assigning undef to attr2 does not produce an error');
79 ok(!$obj->has_attr2, 'attr2 has no value when assigned undef in constructor');
83 my $obj = Bar->new(attr1 => 1234);
84 is($obj->attr1, 1234, 'assigning a defined value during construction works as normal');
85 ok($obj->has_attr1, '...and the predicate returns true as normal');