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';
52 ok($obj->has_attr1, 'attr1 has a value');
53 ok($obj->has_attr2, 'attr2 has a value');
54 is($obj->attr1, 1, 'attr1\'s value is its default');
55 is($obj->attr2, 2, 'attr2\'s value is its default');
59 my $obj = Foo->new(attr1 => undef);
60 ok($obj->has_attr1, 'UT attr1 has a value when assigned undef in constructor');
61 is($obj->attr1, 1, 'attr1\'s value is its default');
62 is($obj->attr2, 2, 'attr2\'s value is its default');
66 my $obj = Foo->new(attr1 => 1234, attr2 => 5678);
67 is($obj->attr1, 1234, 'assigning a defined value during construction works as normal');
68 ok($obj->has_attr1, '...and the predicate returns true as normal');
69 is($obj->attr2, 5678, 'assigning a defined value during construction works as normal');
70 ok($obj->has_attr2, '...and the predicate returns true as normal');
75 note 'Testing class with the entire class being UndefTolerant';
78 ok($obj->has_attr1, 'attr1 has a value');
79 ok($obj->has_attr2, 'attr2 has a value');
80 is($obj->attr1, 1, 'attr1\'s value is its default');
81 is($obj->attr2, 2, 'attr2\'s value is its default');
85 my $obj = Bar->new(attr1 => undef);
86 ok($obj->has_attr1, 'UT attr1 has a value when assigned undef in constructor');
87 is($obj->attr1, 1, 'attr1\'s value is its default');
88 is($obj->attr2, 2, 'attr2\'s value is its default');
92 my $obj = Bar->new(attr1 => 1234, attr2 => 5678);
93 is($obj->attr1, 1234, 'assigning a defined value during construction works as normal');
94 ok($obj->has_attr1, '...and the predicate returns true as normal');
95 is($obj->attr2, 5678, 'assigning a defined value during construction works as normal');
96 ok($obj->has_attr2, '...and the predicate returns true as normal');
100 note 'Default behaviour: mutable classes';
105 note 'Default behaviour: immutable classes';
107 Foo->meta->make_immutable;
108 Bar->meta->make_immutable;
111 local $TODO = 'some immutable cases are not handled yet';
112 # for now, catch errors
113 ok(! exception { do_tests }, 'tests do not die');
115 is(Test::More->builder->current_test, 44, 'if we got here, we can declare victory!');