6 use Test::More tests => 33;
10 use_ok('Class::MOP', ':universal');
13 my $FOO_ATTR = Class::MOP::Attribute->new('$foo');
14 my $BAR_ATTR = Class::MOP::Attribute->new('$bar' => (
17 my $BAZ_ATTR = Class::MOP::Attribute->new('$baz' => (
27 $meta->add_attribute($FOO_ATTR);
28 } '... we added an attribute to Foo successfully';
29 ::ok($meta->has_attribute('$foo'), '... Foo has $foo attribute');
30 ::is($meta->get_attribute('$foo'), $FOO_ATTR, '... got the right attribute back for Foo');
32 ::ok(!$meta->has_method('foo'), '... no accessor created');
40 $meta->add_attribute($BAR_ATTR);
41 } '... we added an attribute to Bar successfully';
42 ::ok($meta->has_attribute('$bar'), '... Bar has $bar attribute');
43 ::is($meta->get_attribute('$bar'), $BAR_ATTR, '... got the right attribute back for Bar');
45 ::ok($meta->has_method('bar'), '... an accessor has been created');
46 ::isa_ok($meta->get_method('bar'), 'Class::MOP::Attribute::Accessor');
54 $meta->add_attribute($BAZ_ATTR);
55 } '... we added an attribute to Baz successfully';
56 ::ok($meta->has_attribute('$baz'), '... Baz has $baz attribute');
57 ::is($meta->get_attribute('$baz'), $BAZ_ATTR, '... got the right attribute back for Baz');
59 ::ok($meta->has_method('get_baz'), '... a reader has been created');
60 ::ok($meta->has_method('set_baz'), '... a writer has been created');
62 ::isa_ok($meta->get_method('get_baz'), 'Class::MOP::Attribute::Accessor');
63 ::isa_ok($meta->get_method('set_baz'), 'Class::MOP::Attribute::Accessor');
68 isa_ok($meta, 'Class::MOP::Class');
71 [ sort { $a->name cmp $b->name } $meta->compute_all_applicable_attributes() ],
77 '... got the right list of applicable attributes for Baz');
80 [ map { $_->associated_class } sort { $a->name cmp $b->name } $meta->compute_all_applicable_attributes() ],
81 [ Bar->meta, Baz->meta, Foo->meta ],
82 '... got the right list of associated classes from the applicable attributes for Baz');
86 $attr = $meta->remove_attribute('$baz');
87 } '... removed the $baz attribute successfully';
88 is($attr, $BAZ_ATTR, '... got the right attribute back for Baz');
90 ok(!$meta->has_attribute('$baz'), '... Baz no longer has $baz attribute');
92 ok(!$meta->has_method('get_baz'), '... a reader has been removed');
93 ok(!$meta->has_method('set_baz'), '... a writer has been removed');
96 [ sort { $a->name cmp $b->name } $meta->compute_all_applicable_attributes() ],
101 '... got the right list of applicable attributes for Baz');
104 [ map { $_->associated_class } sort { $a->name cmp $b->name } $meta->compute_all_applicable_attributes() ],
105 [ Bar->meta, Foo->meta ],
106 '... got the right list of associated classes from the applicable attributes for Baz');
111 $attr = Bar->meta->remove_attribute('$bar');
112 } '... removed the $bar attribute successfully';
113 is($attr, $BAR_ATTR, '... got the right attribute back for Bar');
115 ok(!Bar->meta->has_attribute('$bar'), '... Bar no longer has $bar attribute');
117 ok(!Bar->meta->has_method('bar'), '... a accessor has been removed');
121 [ sort { $a->name cmp $b->name } $meta->compute_all_applicable_attributes() ],
125 '... got the right list of applicable attributes for Baz');
128 [ map { $_->associated_class } sort { $a->name cmp $b->name } $meta->compute_all_applicable_attributes() ],
130 '... got the right list of associated classes from the applicable attributes for Baz');