6 use Test::More tests => 26;
11 require_ok(File::Spec->catdir('examples', 'LazyClass.pod'));
18 ':attribute_metaclass' => 'LazyClass::Attribute',
19 ':instance_metaclass' => 'LazyClass::Instance',
22 BinaryTree->meta->add_attribute('$:node' => (
27 BinaryTree->meta->add_attribute('$:left' => (
29 default => sub { BinaryTree->new() }
32 BinaryTree->meta->add_attribute('$:right' => (
34 default => sub { BinaryTree->new() }
39 bless $class->meta->construct_instance(@_) => $class;
43 my $root = BinaryTree->new(':node' => 0);
44 isa_ok($root, 'BinaryTree');
46 ok(exists($root->{'$:node'}), '... node attribute has been initialized yet');
47 ok(!exists($root->{'$:left'}), '... left attribute has not been initialized yet');
48 ok(!exists($root->{'$:right'}), '... right attribute has not been initialized yet');
50 isa_ok($root->left, 'BinaryTree');
51 isa_ok($root->right, 'BinaryTree');
53 ok(exists($root->{'$:left'}), '... left attribute has now been initialized');
54 ok(exists($root->{'$:right'}), '... right attribute has now been initialized');
56 ok(!exists($root->left->{'$:node'}), '... node attribute has not been initialized yet');
57 ok(!exists($root->left->{'$:left'}), '... left attribute has not been initialized yet');
58 ok(!exists($root->left->{'$:right'}), '... right attribute has not been initialized yet');
60 ok(!exists($root->right->{'$:node'}), '... node attribute has not been initialized yet');
61 ok(!exists($root->right->{'$:left'}), '... left attribute has not been initialized yet');
62 ok(!exists($root->right->{'$:right'}), '... right attribute has not been initialized yet');
64 is($root->left->node(), undef, '... the left node is uninitialized');
66 ok(exists($root->left->{'$:node'}), '... node attribute has now been initialized');
69 is($root->left->node(), 1, '... the left node == 1');
71 ok(!exists($root->left->{'$:left'}), '... left attribute still has not been initialized yet');
72 ok(!exists($root->left->{'$:right'}), '... right attribute still has not been initialized yet');
74 is($root->right->node(), undef, '... the right node is uninitialized');
76 ok(exists($root->right->{'$:node'}), '... node attribute has now been initialized');
78 $root->right->node(2);
79 is($root->right->node(), 2, '... the right node == 1');
81 ok(!exists($root->right->{'$:left'}), '... left attribute still has not been initialized yet');
82 ok(!exists($root->right->{'$:right'}), '... right attribute still has not been initialized yet');