4 use MooseX::UndefTolerant::Attribute ();
11 traits => [ qw(MooseX::UndefTolerant::Attribute)],
14 predicate => 'has_attr1',
20 predicate => 'has_attr2',
28 use MooseX::UndefTolerant;
33 predicate => 'has_attr1',
39 predicate => 'has_attr2',
49 note 'Testing class with a single UndefTolerant attribute';
50 do_tests_with_class('Foo');
53 note 'Testing class with the entire class being UndefTolerant';
54 do_tests_with_class('Bar');
57 sub do_tests_with_class
62 my $obj = $class->new;
63 ok($obj->has_attr1, 'attr1 has a value');
64 ok($obj->has_attr2, 'attr2 has a value');
65 is($obj->attr1, 1, 'attr1\'s value is its default');
66 is($obj->attr2, 2, 'attr2\'s value is its default');
70 my $obj = $class->new(attr1 => undef);
71 ok($obj->has_attr1, 'UT attr1 has a value when assigned undef in constructor');
72 is($obj->attr1, 1, 'attr1\'s value is its default');
73 is($obj->attr2, 2, 'attr2\'s value is its default');
77 my $obj = $class->new(attr1 => 1234, attr2 => 5678);
78 is($obj->attr1, 1234, 'assigning a defined value during construction works as normal');
79 ok($obj->has_attr1, '...and the predicate returns true as normal');
80 is($obj->attr2, 5678, 'assigning a defined value during construction works as normal');
81 ok($obj->has_attr2, '...and the predicate returns true as normal');
85 note 'Default behaviour: mutable classes';
90 note 'Default behaviour: immutable classes';
92 Foo->meta->make_immutable;
93 Bar->meta->make_immutable;
96 local $TODO = 'some immutable cases are not handled yet';
97 # for now, catch errors
98 ok(! exception { do_tests }, 'tests do not die');
100 is(Test::More->builder->current_test, 44, 'if we got here, we can declare victory!');