X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F106_LazyClass_test.t;h=b380d460159d58aad72a6fb18c8cc5f7a821f591;hb=5efa6a46982d17e1ff642e8b97673c6618fa7e6d;hp=8accf6906d530a6d0b84380f60ca3730ae3c9974;hpb=046688ed71ac338d09fad7abdd17833409826113;p=gitmo%2FClass-MOP.git diff --git a/t/106_LazyClass_test.t b/t/106_LazyClass_test.t index 8accf69..b380d46 100644 --- a/t/106_LazyClass_test.t +++ b/t/106_LazyClass_test.t @@ -1,84 +1,83 @@ -#!/usr/bin/perl - use strict; use warnings; -use Test::More tests => 26; +use Test::More; use File::Spec; -BEGIN { - use_ok('Class::MOP'); - require_ok(File::Spec->catdir('examples', 'LazyClass.pod')); +use Class::MOP; + +BEGIN { + require_ok(File::Spec->catfile('examples', 'LazyClass.pod')); } { package BinaryTree; - - sub meta { - LazyClass->initialize($_[0] => ( - ':attribute_metaclass' => 'LazyClass::Attribute' - )); - } - BinaryTree->meta->add_attribute('$:node' => ( + use metaclass ( + 'attribute_metaclass' => 'LazyClass::Attribute', + 'instance_metaclass' => 'LazyClass::Instance', + ); + + BinaryTree->meta->add_attribute('node' => ( accessor => 'node', - init_arg => ':node' + init_arg => 'node' )); - - BinaryTree->meta->add_attribute('$:left' => ( + + BinaryTree->meta->add_attribute('left' => ( reader => 'left', default => sub { BinaryTree->new() } )); - - BinaryTree->meta->add_attribute('$:right' => ( + + BinaryTree->meta->add_attribute('right' => ( reader => 'right', - default => sub { BinaryTree->new() } - )); + default => sub { BinaryTree->new() } + )); sub new { my $class = shift; - bless $class->meta->construct_instance(@_) => $class; + bless $class->meta->new_object(@_) => $class; } } -my $root = BinaryTree->new(':node' => 0); +my $root = BinaryTree->new('node' => 0); isa_ok($root, 'BinaryTree'); -ok(exists($root->{'$:node'}), '... node attribute has been initialized yet'); -ok(!exists($root->{'$:left'}), '... left attribute has not been initialized yet'); -ok(!exists($root->{'$:right'}), '... right attribute has not been initialized yet'); +ok(exists($root->{'node'}), '... node attribute has been initialized yet'); +ok(!exists($root->{'left'}), '... left attribute has not been initialized yet'); +ok(!exists($root->{'right'}), '... right attribute has not been initialized yet'); isa_ok($root->left, 'BinaryTree'); isa_ok($root->right, 'BinaryTree'); -ok(exists($root->{'$:left'}), '... left attribute has now been initialized'); -ok(exists($root->{'$:right'}), '... right attribute has now been initialized'); +ok(exists($root->{'left'}), '... left attribute has now been initialized'); +ok(exists($root->{'right'}), '... right attribute has now been initialized'); -ok(!exists($root->left->{'$:node'}), '... node attribute has not been initialized yet'); -ok(!exists($root->left->{'$:left'}), '... left attribute has not been initialized yet'); -ok(!exists($root->left->{'$:right'}), '... right attribute has not been initialized yet'); +ok(!exists($root->left->{'node'}), '... node attribute has not been initialized yet'); +ok(!exists($root->left->{'left'}), '... left attribute has not been initialized yet'); +ok(!exists($root->left->{'right'}), '... right attribute has not been initialized yet'); -ok(!exists($root->right->{'$:node'}), '... node attribute has not been initialized yet'); -ok(!exists($root->right->{'$:left'}), '... left attribute has not been initialized yet'); -ok(!exists($root->right->{'$:right'}), '... right attribute has not been initialized yet'); +ok(!exists($root->right->{'node'}), '... node attribute has not been initialized yet'); +ok(!exists($root->right->{'left'}), '... left attribute has not been initialized yet'); +ok(!exists($root->right->{'right'}), '... right attribute has not been initialized yet'); is($root->left->node(), undef, '... the left node is uninitialized'); -ok(exists($root->left->{'$:node'}), '... node attribute has now been initialized'); +ok(exists($root->left->{'node'}), '... node attribute has now been initialized'); $root->left->node(1); is($root->left->node(), 1, '... the left node == 1'); -ok(!exists($root->left->{'$:left'}), '... left attribute still has not been initialized yet'); -ok(!exists($root->left->{'$:right'}), '... right attribute still has not been initialized yet'); +ok(!exists($root->left->{'left'}), '... left attribute still has not been initialized yet'); +ok(!exists($root->left->{'right'}), '... right attribute still has not been initialized yet'); is($root->right->node(), undef, '... the right node is uninitialized'); -ok(exists($root->right->{'$:node'}), '... node attribute has now been initialized'); +ok(exists($root->right->{'node'}), '... node attribute has now been initialized'); $root->right->node(2); is($root->right->node(), 2, '... the right node == 1'); -ok(!exists($root->right->{'$:left'}), '... left attribute still has not been initialized yet'); -ok(!exists($root->right->{'$:right'}), '... right attribute still has not been initialized yet'); +ok(!exists($root->right->{'left'}), '... left attribute still has not been initialized yet'); +ok(!exists($root->right->{'right'}), '... right attribute still has not been initialized yet'); +done_testing;