6 use Test::More tests => 28;
13 my $Point = Class::MOP::Class->create('Point' => '0.01' => (
15 Class::MOP::Attribute->new('$.x' => (
19 Class::MOP::Attribute->new('$.y' => (
27 my $instance = $class->meta->construct_instance(@_);
28 bless $instance => $class;
38 my $Point3D = Class::MOP::Class->create('Point3D' => '0.01' => (
39 superclasses => [ 'Point' ],
41 Class::MOP::Attribute->new('$:z' => (
49 $self->SUPER::clear();
54 isa_ok($Point, 'Class::MOP::Class');
55 isa_ok($Point3D, 'Class::MOP::Class');
57 # ... test the classes themselves
59 my $point = Point->new('x' => 2, 'y' => 3);
60 isa_ok($point, 'Point');
64 can_ok($point, 'clear');
67 my $meta = $point->meta;
68 is($meta, Point->meta(), '... got the meta from the instance too');
71 is($point->y, 3, '... the $.y attribute was initialized correctly through the metaobject');
74 is($point->y, 42, '... the $.y attribute was set properly with the accessor');
76 is($point->x, 2, '... the $.x attribute was initialized correctly through the metaobject');
80 } '... cannot write to a read-only accessor';
81 is($point->x, 2, '... the $.x attribute was not altered');
85 is($point->y, 0, '... the $.y attribute was cleared correctly');
86 is($point->x, 0, '... the $.x attribute was cleared correctly');
88 my $point3d = Point3D->new('x' => 1, 'y' => 2, '$:z' => 3);
89 isa_ok($point3d, 'Point3D');
90 isa_ok($point3d, 'Point');
93 my $meta = $point3d->meta;
94 is($meta, Point3D->meta(), '... got the meta from the instance too');
97 can_ok($point3d, 'x');
98 can_ok($point3d, 'y');
99 can_ok($point3d, 'clear');
101 is($point3d->x, 1, '... the $.x attribute was initialized correctly through the metaobject');
102 is($point3d->y, 2, '... the $.y attribute was initialized correctly through the metaobject');
103 is($point3d->{'$:z'}, 3, '... the $:z attribute was initialized correctly through the metaobject');
106 my $point3d = Point3D->new();
107 isa_ok($point3d, 'Point3D');
109 is($point3d->x, undef, '... the $.x attribute was not initialized');
110 is($point3d->y, undef, '... the $.y attribute was not initialized');
111 is($point3d->{'$:z'}, 123, '... the $:z attribute was initialized correctly through the metaobject');