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;
':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() }
));
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,
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'
)),
},
'clear' => sub {
my $self = shift;
- $self->{'$.x'} = 0;
- $self->{'$.y'} = 0;
+ $self->{'x'} = 0;
+ $self->{'y'} = 0;
}
}
));
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();
}
}
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');
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');
}
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'
));
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();
}
}
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');
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');
}
use Carp 'confess';
- BankAccount->meta->add_attribute('$:balance' => (
+ BankAccount->meta->add_attribute('balance' => (
accessor => 'balance',
init_arg => 'balance',
default => 0
use base 'BankAccount';
- CheckingAccount->meta->add_attribute('$:overdraft_account' => (
+ CheckingAccount->meta->add_attribute('overdraft_account' => (
accessor => 'overdraft_account',
init_arg => 'overdraft',
));
use base 'Class::MOP::Package';
__PACKAGE__->meta->add_attribute(
- '%:namespace' => (
+ 'namespace' => (
reader => 'namespace',
default => sub { {} }
)
'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() }
));
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');
our $VERSION = '0.02';
-BinaryTree->meta->add_attribute('$:uid' => (
+BinaryTree->meta->add_attribute('uid' => (
reader => 'getUID',
writer => 'setUID',
default => sub {
}
));
-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',
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',
my ($self, $tree) = @_;
confess "undef right" unless defined $tree;
$tree->setParent($self) if defined $tree;
- $self->{'$:right'} = $tree;
+ $self->{'right'} = $tree;
$self;
}
}