From: Yuval Kogman Date: Fri, 8 Aug 2008 22:28:02 +0000 (+0000) Subject: more $: $. and whatnot cleanups X-Git-Tag: 0_64_01~74 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1aeb4c53a4098bfefdb2c98f81f9b7240d7abbd0;p=gitmo%2FClass-MOP.git more $: $. and whatnot cleanups --- diff --git a/examples/InstanceCountingClass.pod b/examples/InstanceCountingClass.pod index d6a4f31..3cf3eb3 100644 --- a/examples/InstanceCountingClass.pod +++ b/examples/InstanceCountingClass.pod @@ -9,14 +9,14 @@ our $VERSION = '0.03'; use base 'Class::MOP::Class'; -InstanceCountingClass->meta->add_attribute('$:count' => ( +InstanceCountingClass->meta->add_attribute('count' => ( reader => 'get_count', default => 0 )); InstanceCountingClass->meta->add_before_method_modifier('construct_instance' => sub { my ($class) = @_; - $class->{'$:count'}++; + $class->{'count'}++; }); 1; diff --git a/examples/LazyClass.pod b/examples/LazyClass.pod index 560c074..262cd73 100644 --- a/examples/LazyClass.pod +++ b/examples/LazyClass.pod @@ -108,17 +108,17 @@ LazyClass - An example metaclass with lazy initialization ':instance_metaclass' => 'LazyClass::Instance', ); - BinaryTree->meta->add_attribute('$:node' => ( + BinaryTree->meta->add_attribute('node' => ( accessor => '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() } )); diff --git a/t/010_self_introspection.t b/t/010_self_introspection.t index 343ba27..406cf72 100644 --- a/t/010_self_introspection.t +++ b/t/010_self_introspection.t @@ -255,7 +255,7 @@ is_deeply($class_mop_class_meta->get_attribute('method_metaclass')->reader, ok($class_mop_class_meta->get_attribute('method_metaclass')->has_init_arg, '... Class::MOP::Class method_metaclass has a init_arg'); is($class_mop_class_meta->get_attribute('method_metaclass')->init_arg, 'method_metaclass', - '... Class::MOP::Class $:method_metaclass\'s init_arg is method_metaclass'); + '... Class::MOP::Class method_metaclass\'s init_arg is method_metaclass'); ok($class_mop_class_meta->get_attribute('method_metaclass')->has_default, '... Class::MOP::Class method_metaclass has a default'); is($class_mop_class_meta->get_attribute('method_metaclass')->default, diff --git a/t/011_create_class.t b/t/011_create_class.t index 1557927..874c81b 100644 --- a/t/011_create_class.t +++ b/t/011_create_class.t @@ -13,11 +13,11 @@ BEGIN { my $Point = Class::MOP::Class->create('Point' => ( version => '0.01', attributes => [ - Class::MOP::Attribute->new('$.x' => ( + Class::MOP::Attribute->new('x' => ( reader => 'x', init_arg => 'x' )), - Class::MOP::Attribute->new('$.y' => ( + Class::MOP::Attribute->new('y' => ( accessor => 'y', init_arg => 'y' )), @@ -30,8 +30,8 @@ my $Point = Class::MOP::Class->create('Point' => ( }, 'clear' => sub { my $self = shift; - $self->{'$.x'} = 0; - $self->{'$.y'} = 0; + $self->{'x'} = 0; + $self->{'y'} = 0; } } )); @@ -40,14 +40,14 @@ my $Point3D = Class::MOP::Class->create('Point3D' => ( version => '0.01', superclasses => [ 'Point' ], attributes => [ - Class::MOP::Attribute->new('$:z' => ( + Class::MOP::Attribute->new('z' => ( default => 123 )), ], methods => { 'clear' => sub { my $self = shift; - $self->{'$:z'} = 0; + $self->{'z'} = 0; $self->SUPER::clear(); } } @@ -70,24 +70,24 @@ can_ok($point, 'clear'); is($meta, Point->meta(), '... got the meta from the instance too'); } -is($point->y, 3, '... the $.y attribute was initialized correctly through the metaobject'); +is($point->y, 3, '... the y attribute was initialized correctly through the metaobject'); $point->y(42); -is($point->y, 42, '... the $.y attribute was set properly with the accessor'); +is($point->y, 42, '... the y attribute was set properly with the accessor'); -is($point->x, 2, '... the $.x attribute was initialized correctly through the metaobject'); +is($point->x, 2, '... the x attribute was initialized correctly through the metaobject'); dies_ok { $point->x(42); } '... cannot write to a read-only accessor'; -is($point->x, 2, '... the $.x attribute was not altered'); +is($point->x, 2, '... the x attribute was not altered'); $point->clear(); -is($point->y, 0, '... the $.y attribute was cleared correctly'); -is($point->x, 0, '... the $.x attribute was cleared correctly'); +is($point->y, 0, '... the y attribute was cleared correctly'); +is($point->x, 0, '... the x attribute was cleared correctly'); -my $point3d = Point3D->new('x' => 1, 'y' => 2, '$:z' => 3); +my $point3d = Point3D->new('x' => 1, 'y' => 2, 'z' => 3); isa_ok($point3d, 'Point3D'); isa_ok($point3d, 'Point'); @@ -100,17 +100,17 @@ can_ok($point3d, 'x'); can_ok($point3d, 'y'); can_ok($point3d, 'clear'); -is($point3d->x, 1, '... the $.x attribute was initialized correctly through the metaobject'); -is($point3d->y, 2, '... the $.y attribute was initialized correctly through the metaobject'); -is($point3d->{'$:z'}, 3, '... the $:z attribute was initialized correctly through the metaobject'); +is($point3d->x, 1, '... the x attribute was initialized correctly through the metaobject'); +is($point3d->y, 2, '... the y attribute was initialized correctly through the metaobject'); +is($point3d->{'z'}, 3, '... the z attribute was initialized correctly through the metaobject'); { my $point3d = Point3D->new(); isa_ok($point3d, 'Point3D'); - is($point3d->x, undef, '... the $.x attribute was not initialized'); - is($point3d->y, undef, '... the $.y attribute was not initialized'); - is($point3d->{'$:z'}, 123, '... the $:z attribute was initialized correctly through the metaobject'); + is($point3d->x, undef, '... the x attribute was not initialized'); + is($point3d->y, undef, '... the y attribute was not initialized'); + is($point3d->{'z'}, 123, '... the z attribute was initialized correctly through the metaobject'); } diff --git a/t/013_add_attribute_alternate.t b/t/013_add_attribute_alternate.t index ca70fe2..03d6d16 100644 --- a/t/013_add_attribute_alternate.t +++ b/t/013_add_attribute_alternate.t @@ -14,12 +14,12 @@ BEGIN { package Point; use metaclass; - Point->meta->add_attribute('$.x' => ( + Point->meta->add_attribute('x' => ( reader => 'x', init_arg => 'x' )); - Point->meta->add_attribute('$.y' => ( + Point->meta->add_attribute('y' => ( accessor => 'y', init_arg => 'y' )); @@ -31,20 +31,20 @@ BEGIN { sub clear { my $self = shift; - $self->{'$.x'} = 0; - $self->{'$.y'} = 0; + $self->{'x'} = 0; + $self->{'y'} = 0; } package Point3D; our @ISA = ('Point'); - Point3D->meta->add_attribute('$:z' => ( + Point3D->meta->add_attribute('z' => ( default => 123 )); sub clear { my $self = shift; - $self->{'$:z'} = 0; + $self->{'z'} = 0; $self->SUPER::clear(); } } @@ -66,24 +66,24 @@ can_ok($point, 'clear'); is($meta, Point->meta(), '... got the meta from the instance too'); } -is($point->y, 3, '... the $.y attribute was initialized correctly through the metaobject'); +is($point->y, 3, '... the y attribute was initialized correctly through the metaobject'); $point->y(42); -is($point->y, 42, '... the $.y attribute was set properly with the accessor'); +is($point->y, 42, '... the y attribute was set properly with the accessor'); -is($point->x, 2, '... the $.x attribute was initialized correctly through the metaobject'); +is($point->x, 2, '... the x attribute was initialized correctly through the metaobject'); dies_ok { $point->x(42); } '... cannot write to a read-only accessor'; -is($point->x, 2, '... the $.x attribute was not altered'); +is($point->x, 2, '... the x attribute was not altered'); $point->clear(); -is($point->y, 0, '... the $.y attribute was cleared correctly'); -is($point->x, 0, '... the $.x attribute was cleared correctly'); +is($point->y, 0, '... the y attribute was cleared correctly'); +is($point->x, 0, '... the x attribute was cleared correctly'); -my $point3d = Point3D->new('x' => 1, 'y' => 2, '$:z' => 3); +my $point3d = Point3D->new('x' => 1, 'y' => 2, 'z' => 3); isa_ok($point3d, 'Point3D'); isa_ok($point3d, 'Point'); @@ -96,16 +96,16 @@ can_ok($point3d, 'x'); can_ok($point3d, 'y'); can_ok($point3d, 'clear'); -is($point3d->x, 1, '... the $.x attribute was initialized correctly through the metaobject'); -is($point3d->y, 2, '... the $.y attribute was initialized correctly through the metaobject'); -is($point3d->{'$:z'}, 3, '... the $:z attribute was initialized correctly through the metaobject'); +is($point3d->x, 1, '... the x attribute was initialized correctly through the metaobject'); +is($point3d->y, 2, '... the y attribute was initialized correctly through the metaobject'); +is($point3d->{'z'}, 3, '... the z attribute was initialized correctly through the metaobject'); { my $point3d = Point3D->new(); isa_ok($point3d, 'Point3D'); - is($point3d->x, undef, '... the $.x attribute was not initialized'); - is($point3d->y, undef, '... the $.y attribute was not initialized'); - is($point3d->{'$:z'}, 123, '... the $:z attribute was initialized correctly through the metaobject'); + is($point3d->x, undef, '... the x attribute was not initialized'); + is($point3d->y, undef, '... the y attribute was not initialized'); + is($point3d->{'z'}, 123, '... the z attribute was initialized correctly through the metaobject'); } diff --git a/t/017_add_method_modifier.t b/t/017_add_method_modifier.t index 646c396..e2e4422 100644 --- a/t/017_add_method_modifier.t +++ b/t/017_add_method_modifier.t @@ -19,7 +19,7 @@ BEGIN { use Carp 'confess'; - BankAccount->meta->add_attribute('$:balance' => ( + BankAccount->meta->add_attribute('balance' => ( accessor => 'balance', init_arg => 'balance', default => 0 @@ -48,7 +48,7 @@ BEGIN { use base 'BankAccount'; - CheckingAccount->meta->add_attribute('$:overdraft_account' => ( + CheckingAccount->meta->add_attribute('overdraft_account' => ( accessor => 'overdraft_account', init_arg => 'overdraft', )); diff --git a/t/081_meta_package_extension.t b/t/081_meta_package_extension.t index 409cdac..d107361 100644 --- a/t/081_meta_package_extension.t +++ b/t/081_meta_package_extension.t @@ -22,7 +22,7 @@ BEGIN { use base 'Class::MOP::Package'; __PACKAGE__->meta->add_attribute( - '%:namespace' => ( + 'namespace' => ( reader => 'namespace', default => sub { {} } ) diff --git a/t/106_LazyClass_test.t b/t/106_LazyClass_test.t index 866cbe1..c17b490 100644 --- a/t/106_LazyClass_test.t +++ b/t/106_LazyClass_test.t @@ -19,17 +19,17 @@ BEGIN { 'instance_metaclass' => 'LazyClass::Instance', ); - BinaryTree->meta->add_attribute('$:node' => ( + BinaryTree->meta->add_attribute('node' => ( accessor => '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() } )); @@ -43,41 +43,41 @@ BEGIN { 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'); diff --git a/t/lib/BinaryTree.pm b/t/lib/BinaryTree.pm index 23f5863..539800a 100644 --- a/t/lib/BinaryTree.pm +++ b/t/lib/BinaryTree.pm @@ -9,7 +9,7 @@ use metaclass; our $VERSION = '0.02'; -BinaryTree->meta->add_attribute('$:uid' => ( +BinaryTree->meta->add_attribute('uid' => ( reader => 'getUID', writer => 'setUID', default => sub { @@ -18,21 +18,21 @@ BinaryTree->meta->add_attribute('$:uid' => ( } )); -BinaryTree->meta->add_attribute('$:node' => ( +BinaryTree->meta->add_attribute('node' => ( reader => 'getNodeValue', writer => 'setNodeValue', clearer => 'clearNodeValue', init_arg => ':node' )); -BinaryTree->meta->add_attribute('$:parent' => ( +BinaryTree->meta->add_attribute('parent' => ( predicate => 'hasParent', reader => 'getParent', writer => 'setParent', clearer => 'clearParent', )); -BinaryTree->meta->add_attribute('$:left' => ( +BinaryTree->meta->add_attribute('left' => ( predicate => 'hasLeft', clearer => 'clearLeft', reader => 'getLeft', @@ -41,13 +41,13 @@ BinaryTree->meta->add_attribute('$:left' => ( my ($self, $tree) = @_; confess "undef left" unless defined $tree; $tree->setParent($self) if defined $tree; - $self->{'$:left'} = $tree; + $self->{'left'} = $tree; $self; } }, )); -BinaryTree->meta->add_attribute('$:right' => ( +BinaryTree->meta->add_attribute('right' => ( predicate => 'hasRight', clearer => 'clearRight', reader => 'getRight', @@ -56,7 +56,7 @@ BinaryTree->meta->add_attribute('$:right' => ( my ($self, $tree) = @_; confess "undef right" unless defined $tree; $tree->setParent($self) if defined $tree; - $self->{'$:right'} = $tree; + $self->{'right'} = $tree; $self; } }