8 use Test::More tests => 17;
16 This tests that when an attribute of the same name
17 is added to a class, that it will remove the old
26 Foo->meta->add_attribute('bar' =>
31 ::can_ok('Foo', 'get_bar');
32 ::can_ok('Foo', 'set_bar');
33 ::ok(Foo->meta->has_attribute('bar'), '... Foo has the attribute bar');
35 my $bar_attr = Foo->meta->get_attribute('bar');
37 ::is($bar_attr->reader, 'get_bar', '... the bar attribute has the reader get_bar');
38 ::is($bar_attr->writer, 'set_bar', '... the bar attribute has the writer set_bar');
39 ::is($bar_attr->associated_class, Foo->meta, '... and the bar attribute is associated with Foo->meta');
41 Foo->meta->add_attribute('bar' =>
42 reader => 'assign_bar'
45 ::ok(!Foo->can('get_bar'), '... Foo no longer has the get_bar method');
46 ::ok(!Foo->can('set_bar'), '... Foo no longer has the set_bar method');
47 ::can_ok('Foo', 'assign_bar');
48 ::ok(Foo->meta->has_attribute('bar'), '... Foo still has the attribute bar');
50 my $bar_attr2 = Foo->meta->get_attribute('bar');
52 ::isnt($bar_attr, $bar_attr2, '... this is a new bar attribute');
53 ::isnt($bar_attr->associated_class, Foo->meta, '... and the old bar attribute is no longer associated with Foo->meta');
55 ::is($bar_attr2->associated_class, Foo->meta, '... and the new bar attribute *is* associated with Foo->meta');
57 ::isnt($bar_attr2->reader, 'get_bar', '... the bar attribute no longer has the reader get_bar');
58 ::isnt($bar_attr2->reader, 'set_bar', '... the bar attribute no longer has the reader set_bar');
59 ::is($bar_attr2->reader, 'assign_bar', '... the bar attribute now has the reader assign_bar');