Subject: | Incorrect default handling when attributes are inherited |
B1 and B2 are the same, except that B2 redeclares the 'a' attribute. This is causing the default to be retained from the parent class (A), rather than being reset to the correct value from B1.
Test program:
use Class::AutoClass;
use Test::More tests=>5;
package A;
@ISA=qw(Class::AutoClass);
@AUTO_ATTRIBUTES=qw(a);
%DEFAULTS=(a=>'a default from A');
Class::AutoClass::declare(__PACKAGE__);
package B1;
@ISA=qw(A);
@AUTO_ATTRIBUTES=qw(b);
%DEFAULTS=(a=>'a default from B1',
b=>'b default from B1');
Class::AutoClass::declare(__PACKAGE__);
package B2;
@ISA=qw(A);
@AUTO_ATTRIBUTES=qw(a b);
%DEFAULTS=(a=>'a default from B2',
b=>'b default from B2');
Class::AutoClass::declare(__PACKAGE__);
package main;
my $a=new A;
my $b1=new B1;
my $b2=new B2;
ok($a->a eq 'a default from A','$a ->a');
ok($b1->a eq 'a default from B1','$b1->a');
ok($b1->b eq 'b default from B1','$b1->b');
ok($b2->a eq 'a default from B2','$b2->a') or diag('Wrong \$b2->a: ',$b2->a,"\n");
ok($b2->b eq 'b default from B2','$b2->b');
Output:
1..5
ok 1 - $a ->a
ok 2 - $b1->a
ok 3 - $b1->b
not ok 4 - $b2->a
# Failed test (bug_ancestors.t at line 32)
# Wrong \$b2->a: # a default from A#
ok 5 - $b2->b
# Looks like you failed 1 tests of 5.