4 use Test::More tests => 25;
8 require_ok(File::Spec->catfile('examples', 'LazyClass.pod'));
15 'attribute_metaclass' => 'LazyClass::Attribute',
16 'instance_metaclass' => 'LazyClass::Instance',
19 BinaryTree->meta->add_attribute('node' => (
24 BinaryTree->meta->add_attribute('left' => (
26 default => sub { BinaryTree->new() }
29 BinaryTree->meta->add_attribute('right' => (
31 default => sub { BinaryTree->new() }
36 bless $class->meta->new_object(@_) => $class;
40 my $root = BinaryTree->new('node' => 0);
41 isa_ok($root, 'BinaryTree');
43 ok(exists($root->{'node'}), '... node attribute has been initialized yet');
44 ok(!exists($root->{'left'}), '... left attribute has not been initialized yet');
45 ok(!exists($root->{'right'}), '... right attribute has not been initialized yet');
47 isa_ok($root->left, 'BinaryTree');
48 isa_ok($root->right, 'BinaryTree');
50 ok(exists($root->{'left'}), '... left attribute has now been initialized');
51 ok(exists($root->{'right'}), '... right attribute has now been initialized');
53 ok(!exists($root->left->{'node'}), '... node attribute has not been initialized yet');
54 ok(!exists($root->left->{'left'}), '... left attribute has not been initialized yet');
55 ok(!exists($root->left->{'right'}), '... right attribute has not been initialized yet');
57 ok(!exists($root->right->{'node'}), '... node attribute has not been initialized yet');
58 ok(!exists($root->right->{'left'}), '... left attribute has not been initialized yet');
59 ok(!exists($root->right->{'right'}), '... right attribute has not been initialized yet');
61 is($root->left->node(), undef, '... the left node is uninitialized');
63 ok(exists($root->left->{'node'}), '... node attribute has now been initialized');
66 is($root->left->node(), 1, '... the left node == 1');
68 ok(!exists($root->left->{'left'}), '... left attribute still has not been initialized yet');
69 ok(!exists($root->left->{'right'}), '... right attribute still has not been initialized yet');
71 is($root->right->node(), undef, '... the right node is uninitialized');
73 ok(exists($root->right->{'node'}), '... node attribute has now been initialized');
75 $root->right->node(2);
76 is($root->right->node(), 2, '... the right node == 1');
78 ok(!exists($root->right->{'left'}), '... left attribute still has not been initialized yet');
79 ok(!exists($root->right->{'right'}), '... right attribute still has not been initialized yet');