6 use Test::More tests => 27;
10 use_ok('Class::MOP', ':universal');
16 Point->meta->add_attribute('$.x' => (
21 Point->meta->add_attribute('$.y' => (
28 bless $class->meta->construct_instance(@_) => $class;
40 Point3D->meta->add_attribute('$:z' => (
47 $self->SUPER::clear();
51 isa_ok(Point->meta, 'Class::MOP::Class');
52 isa_ok(Point3D->meta, 'Class::MOP::Class');
54 # ... test the classes themselves
56 my $point = Point->new('x' => 2, 'y' => 3);
57 isa_ok($point, 'Point');
61 can_ok($point, 'clear');
64 my $meta = $point->meta;
65 is($meta, Point->meta(), '... got the meta from the instance too');
68 is($point->y, 3, '... the $.y attribute was initialized correctly through the metaobject');
71 is($point->y, 42, '... the $.y attribute was set properly with the accessor');
73 is($point->x, 2, '... the $.x attribute was initialized correctly through the metaobject');
76 is($point->x, 2, '... the $.x attribute was not altered');
80 is($point->y, 0, '... the $.y attribute was cleared correctly');
81 is($point->x, 0, '... the $.x attribute was cleared correctly');
83 my $point3d = Point3D->new('x' => 1, 'y' => 2, '$:z' => 3);
84 isa_ok($point3d, 'Point3D');
85 isa_ok($point3d, 'Point');
88 my $meta = $point3d->meta;
89 is($meta, Point3D->meta(), '... got the meta from the instance too');
92 can_ok($point3d, 'x');
93 can_ok($point3d, 'y');
94 can_ok($point3d, 'clear');
96 is($point3d->x, 1, '... the $.x attribute was initialized correctly through the metaobject');
97 is($point3d->y, 2, '... the $.y attribute was initialized correctly through the metaobject');
98 is($point3d->{'$:z'}, 3, '... the $:z attribute was initialized correctly through the metaobject');
101 my $point3d = Point3D->new();
102 isa_ok($point3d, 'Point3D');
104 is($point3d->x, undef, '... the $.x attribute was not initialized');
105 is($point3d->y, undef, '... the $.y attribute was not initialized');
106 is($point3d->{'$:z'}, 123, '... the $:z attribute was initialized correctly through the metaobject');