6 use Test::More tests => 28;
13 my $Point = Class::MOP::Class->create('Point' => (
16 Class::MOP::Attribute->new('$.x' => (
20 Class::MOP::Attribute->new('$.y' => (
28 my $instance = $class->meta->construct_instance(@_);
29 bless $instance => $class;
39 my $Point3D = Class::MOP::Class->create('Point3D' => (
41 superclasses => [ 'Point' ],
43 Class::MOP::Attribute->new('$:z' => (
51 $self->SUPER::clear();
56 isa_ok($Point, 'Class::MOP::Class');
57 isa_ok($Point3D, 'Class::MOP::Class');
59 # ... test the classes themselves
61 my $point = Point->new('x' => 2, 'y' => 3);
62 isa_ok($point, 'Point');
66 can_ok($point, 'clear');
69 my $meta = $point->meta;
70 is($meta, Point->meta(), '... got the meta from the instance too');
73 is($point->y, 3, '... the $.y attribute was initialized correctly through the metaobject');
76 is($point->y, 42, '... the $.y attribute was set properly with the accessor');
78 is($point->x, 2, '... the $.x attribute was initialized correctly through the metaobject');
82 } '... cannot write to a read-only accessor';
83 is($point->x, 2, '... the $.x attribute was not altered');
87 is($point->y, 0, '... the $.y attribute was cleared correctly');
88 is($point->x, 0, '... the $.x attribute was cleared correctly');
90 my $point3d = Point3D->new('x' => 1, 'y' => 2, '$:z' => 3);
91 isa_ok($point3d, 'Point3D');
92 isa_ok($point3d, 'Point');
95 my $meta = $point3d->meta;
96 is($meta, Point3D->meta(), '... got the meta from the instance too');
99 can_ok($point3d, 'x');
100 can_ok($point3d, 'y');
101 can_ok($point3d, 'clear');
103 is($point3d->x, 1, '... the $.x attribute was initialized correctly through the metaobject');
104 is($point3d->y, 2, '... the $.y attribute was initialized correctly through the metaobject');
105 is($point3d->{'$:z'}, 3, '... the $:z attribute was initialized correctly through the metaobject');
108 my $point3d = Point3D->new();
109 isa_ok($point3d, 'Point3D');
111 is($point3d->x, undef, '... the $.x attribute was not initialized');
112 is($point3d->y, undef, '... the $.y attribute was not initialized');
113 is($point3d->{'$:z'}, 123, '... the $:z attribute was initialized correctly through the metaobject');