5 use MooseX::UndefTolerant::Attribute ();
12 traits => [ qw(MooseX::UndefTolerant::Attribute)],
15 predicate => 'has_attr1',
21 predicate => 'has_attr2',
27 predicate => 'has_attr3',
35 use MooseX::UndefTolerant;
40 predicate => 'has_attr1',
46 predicate => 'has_attr2',
52 predicate => 'has_attr3',
62 note 'Default behaviour: ',
63 (Foo->meta->is_immutable ? 'im' : '') . 'mutable classes', "\n";
65 note 'Testing class with a single UndefTolerant attribute';
66 do_tests_with_class('Foo');
69 note 'Testing class with the entire class being UndefTolerant';
70 do_tests_with_class('Bar');
73 sub do_tests_with_class
78 my $obj = $class->new;
79 ok($obj->has_attr1, 'attr1 has a value');
80 ok($obj->has_attr2, 'attr2 has a value');
81 ok($obj->has_attr3, 'attr3 has a value');
83 is($obj->attr1, 1, 'attr1\'s value is its default');
84 is($obj->attr2, 2, 'attr2\'s value is its default');
85 is($obj->attr3, 3, 'attr3\'s value is its default');
92 my $obj = $class->new(attr1 => undef, attr3 => undef);
94 local $TODO = 'not sure why this fails still... needs attr trait rewrite';
95 ok($obj->has_attr1, 'UT attr1 has a value when assigned undef in constructor');
96 ok($obj->has_attr3, 'attr3 retains its undef value when assigned undef in constructor');
98 is($obj->attr1, 1, 'attr1\'s value is its default');
101 is($obj->attr2, 2, 'attr2\'s value is its default');
102 is($obj->attr3, undef, 'attr3\'s value is not its default (explicitly set)');
104 $TODO = 'some immutable cases are not handled yet; see CAVEATS'
105 if $class->meta->is_immutable;
107 is($e, undef, 'these tests do not die');
111 my $obj = $class->new(attr1 => 1234, attr2 => 5678, attr3 => 9012);
112 is($obj->attr1, 1234, 'assigning a defined value during construction works as normal');
113 ok($obj->has_attr1, '...and the predicate returns true as normal');
115 is($obj->attr2, 5678, 'assigning a defined value during construction works as normal');
116 ok($obj->has_attr2, '...and the predicate returns true as normal');
118 is($obj->attr3, 9012, 'assigning a defined value during construction works as normal');
119 ok($obj->has_attr3, '...and the predicate returns true as normal');
128 local $TODO = 'some cases are still not handled yet; see CAVEATS';
129 is(Test::More->builder->current_test, 98, 'if we got here, we can declare victory!');