9 my $Point = Class::MOP::Class->create('Point' => (
12 Class::MOP::Attribute->new('x' => (
16 Class::MOP::Attribute->new('y' => (
24 my $instance = $class->meta->new_object(@_);
25 bless $instance => $class;
35 my $Point3D = Class::MOP::Class->create('Point3D' => (
37 superclasses => [ 'Point' ],
39 Class::MOP::Attribute->new('z' => (
47 $self->SUPER::clear();
52 isa_ok($Point, 'Class::MOP::Class');
53 isa_ok($Point3D, 'Class::MOP::Class');
55 # ... test the classes themselves
57 my $point = Point->new('x' => 2, 'y' => 3);
58 isa_ok($point, 'Point');
62 can_ok($point, 'clear');
65 my $meta = $point->meta;
66 is($meta, Point->meta(), '... got the meta from the instance too');
69 is($point->y, 3, '... the y attribute was initialized correctly through the metaobject');
72 is($point->y, 42, '... the y attribute was set properly with the accessor');
74 is($point->x, 2, '... the x attribute was initialized correctly through the metaobject');
78 }, undef, '... cannot write to a read-only accessor' );
79 is($point->x, 2, '... the x attribute was not altered');
83 is($point->y, 0, '... the y attribute was cleared correctly');
84 is($point->x, 0, '... the x attribute was cleared correctly');
86 my $point3d = Point3D->new('x' => 1, 'y' => 2, 'z' => 3);
87 isa_ok($point3d, 'Point3D');
88 isa_ok($point3d, 'Point');
91 my $meta = $point3d->meta;
92 is($meta, Point3D->meta(), '... got the meta from the instance too');
95 can_ok($point3d, 'x');
96 can_ok($point3d, 'y');
97 can_ok($point3d, 'clear');
99 is($point3d->x, 1, '... the x attribute was initialized correctly through the metaobject');
100 is($point3d->y, 2, '... the y attribute was initialized correctly through the metaobject');
101 is($point3d->{'z'}, 3, '... the z attribute was initialized correctly through the metaobject');
104 my $point3d = Point3D->new();
105 isa_ok($point3d, 'Point3D');
107 is($point3d->x, undef, '... the x attribute was not initialized');
108 is($point3d->y, undef, '... the y attribute was not initialized');
109 is($point3d->{'z'}, 123, '... the z attribute was initialized correctly through the metaobject');