6 use Test::More tests => 41;
21 type_constraint => Int(),
26 type_constraint => Int(),
42 has 'z' => (type_constraint => Int());
44 after 'clear' => sub {
51 my $point = Point->new(x => 1, y => 2);
52 isa_ok($point, 'Point');
53 isa_ok($point, 'Moose::Object');
55 is($point->x, 1, '... got the right value for x');
56 is($point->y, 2, '... got the right value for y');
59 is($point->y, 10, '... got the right (changed) value for y');
63 } '... cannot assign a non-Int to y';
66 is($point->x, 1, '... got the right (un-changed) value for x');
70 is($point->x, 0, '... got the right (cleared) value for x');
71 is($point->y, 0, '... got the right (cleared) value for y');
73 # check the type constraints on the constructor
76 Point->new(x => 0, y => 0);
77 } '... can assign a 0 to x and y';
80 Point->new(x => 10, y => 'Foo');
81 } '... cannot assign a non-Int to y';
84 Point->new(x => 'Foo', y => 10);
85 } '... cannot assign a non-Int to x';
89 my $point3d = Point3D->new(x => 10, y => 15, z => 3);
90 isa_ok($point3d, 'Point3D');
91 isa_ok($point3d, 'Point');
92 isa_ok($point3d, 'Moose::Object');
94 is($point3d->x, 10, '... got the right value for x');
95 is($point3d->y, 15, '... got the right value for y');
96 is($point3d->{'z'}, 3, '... got the right value for z');
100 } '... there is no method for z';
104 is($point3d->x, 0, '... got the right (cleared) value for x');
105 is($point3d->y, 0, '... got the right (cleared) value for y');
106 is($point3d->{'z'}, 0, '... got the right (cleared) value for z');
109 Point3D->new(x => 10, y => 'Foo', z => 3);
110 } '... cannot assign a non-Int to y';
113 Point3D->new(x => 'Foo', y => 10, z => 3);
114 } '... cannot assign a non-Int to x';
117 Point3D->new(x => 0, y => 10, z => 'Bar');
118 } '... cannot assign a non-Int to z';
120 # test some class introspection
122 can_ok('Point', 'meta');
123 isa_ok(Point->meta, 'Moose::Meta::Class');
125 can_ok('Point3D', 'meta');
126 isa_ok(Point3D->meta, 'Moose::Meta::Class');
128 isnt(Point->meta, Point3D->meta, '... they are different metaclasses as well');
133 [ Point->meta->superclasses ],
135 '... Point got the automagic base class');
137 my @Point_methods = qw(x y clear);
138 my @Point_attrs = ('x', 'y');
141 [ sort @Point_methods ],
142 [ sort Point->meta->get_method_list() ],
143 '... we match the method list for Point');
146 [ sort @Point_attrs ],
147 [ sort Point->meta->get_attribute_list() ],
148 '... we match the attribute list for Point');
150 foreach my $method (@Point_methods) {
151 ok(Point->meta->has_method($method), '... Point has the method "' . $method . '"');
157 [ Point3D->meta->superclasses ],
159 '... Point3D gets the parent given to it');
161 my @Point3D_methods = qw(clear);
162 my @Point3D_attrs = ('z');
165 [ sort @Point3D_methods ],
166 [ sort Point3D->meta->get_method_list() ],
167 '... we match the method list for Point3D');
170 [ sort @Point3D_attrs ],
171 [ sort Point3D->meta->get_attribute_list() ],
172 '... we match the attribute list for Point3D');
174 foreach my $method (@Point3D_methods) {
175 ok(Point3D->meta->has_method($method), '... Point3D has the method "' . $method . '"');