X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F013_add_attribute_alternate.t;h=23ea0fe0d95268a1a9fe46343317927ea4595ecb;hb=00c93f7a35c441cd7101c95c185c9f2bfe62a3b2;hp=03cd2df75a23be18f1ac2995652d19d5615d0d9d;hpb=aa448b163f4882fc3e4b92a1c1f22e3c9ad9f933;p=gitmo%2FClass-MOP.git diff --git a/t/013_add_attribute_alternate.t b/t/013_add_attribute_alternate.t index 03cd2df..23ea0fe 100644 --- a/t/013_add_attribute_alternate.t +++ b/t/013_add_attribute_alternate.t @@ -6,20 +6,18 @@ use warnings; use Test::More tests => 27; use Test::Exception; -BEGIN { - use_ok('Class::MOP'); -} +use Class::MOP; { 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 +29,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,22 +64,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'); -$point->x(42); -is($point->x, 2, '... the $.x attribute was not altered'); +dies_ok { + $point->x(42); +} '... cannot write to a read-only accessor'; +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'); @@ -94,16 +94,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'); }