6 use Test::More tests => 26;
11 require_ok(File::Spec->catdir('examples', 'LazyClass.pod'));
18 LazyClass->initialize($_[0] => (
19 ':attribute_metaclass' => 'LazyClass::Attribute'
23 BinaryTree->meta->add_attribute('$:node' => (
28 BinaryTree->meta->add_attribute('$:left' => (
30 default => sub { BinaryTree->new() }
33 BinaryTree->meta->add_attribute('$:right' => (
35 default => sub { BinaryTree->new() }
40 bless $class->meta->construct_instance(@_) => $class;
44 my $root = BinaryTree->new(':node' => 0);
45 isa_ok($root, 'BinaryTree');
47 ok(exists($root->{'$:node'}), '... node attribute has been initialized yet');
48 ok(!exists($root->{'$:left'}), '... left attribute has not been initialized yet');
49 ok(!exists($root->{'$:right'}), '... right attribute has not been initialized yet');
51 isa_ok($root->left, 'BinaryTree');
52 isa_ok($root->right, 'BinaryTree');
54 ok(exists($root->{'$:left'}), '... left attribute has now been initialized');
55 ok(exists($root->{'$:right'}), '... right attribute has now been initialized');
57 ok(!exists($root->left->{'$:node'}), '... node attribute has not been initialized yet');
58 ok(!exists($root->left->{'$:left'}), '... left attribute has not been initialized yet');
59 ok(!exists($root->left->{'$:right'}), '... right attribute has not been initialized yet');
61 ok(!exists($root->right->{'$:node'}), '... node attribute has not been initialized yet');
62 ok(!exists($root->right->{'$:left'}), '... left attribute has not been initialized yet');
63 ok(!exists($root->right->{'$:right'}), '... right attribute has not been initialized yet');
65 is($root->left->node(), undef, '... the left node is uninitialized');
67 ok(exists($root->left->{'$:node'}), '... node attribute has now been initialized');
70 is($root->left->node(), 1, '... the left node == 1');
72 ok(!exists($root->left->{'$:left'}), '... left attribute still has not been initialized yet');
73 ok(!exists($root->left->{'$:right'}), '... right attribute still has not been initialized yet');
75 is($root->right->node(), undef, '... the right node is uninitialized');
77 ok(exists($root->right->{'$:node'}), '... node attribute has now been initialized');
79 $root->right->node(2);
80 is($root->right->node(), 2, '... the right node == 1');
82 ok(!exists($root->right->{'$:left'}), '... left attribute still has not been initialized yet');
83 ok(!exists($root->right->{'$:right'}), '... right attribute still has not been initialized yet');