X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FClassData.pm;fp=lib%2FCatalyst%2FClassData.pm;h=87b68c9952a85454bfb9d91c3ed48c1accb6a261;hp=6b14d7ef9988bfe0436a883cf19e6ff7b830fb26;hb=76721d3c6f8660effa365b8c1574b1e87f4973cb;hpb=4e37bcd991f09d8215fa2c79122d187ec411864c diff --git a/lib/Catalyst/ClassData.pm b/lib/Catalyst/ClassData.pm index 6b14d7e..87b68c9 100644 --- a/lib/Catalyst/ClassData.pm +++ b/lib/Catalyst/ClassData.pm @@ -14,8 +14,20 @@ sub mk_classdata { my $accessor = sub { my $pkg = ref $_[0] || $_[0]; my $meta = $pkg->Class::MOP::Object::meta(); - if (@_ > 1){ + if (@_ > 1) { $meta->namespace->{$attribute} = \$_[1]; + no strict 'refs'; + if (! *{"${pkg}::${attribute}"}{CODE} ) { + foreach my $super ( $meta->linearized_isa ) { + # If there is a code symbol for this class data in a parent class, but not in our + # class then copy it into our package. This is evil. + my $parent_symbol = *{"${super}::${attribute}"}{CODE} ? \&{"${super}::${attribute}"} : undef; + if (defined $parent_symbol) { + *{"${pkg}::${attribute}"} = $parent_symbol; + last; + } + } + } return $_[1]; } @@ -29,14 +41,6 @@ sub mk_classdata { return ${$v}; } else { foreach my $super ( $meta->linearized_isa ) { - # If there is a code symbol for this attr in a parent class, - # then copy it into our package. Is this the correct - # fix for C::D::I back-compat? (t0m) - my $parent_symbol = *{"${super}::${attribute}"}{CODE} ? \&{"${super}::${attribute}"} : undef; - # FIXME - this is over-enthusiastic? - if (defined $parent_symbol) { - *{"${pkg}::${attribute}"} = $parent_symbol; - } # tighter version of same after # my $super_meta = Moose::Meta::Class->initialize($super); my $v = ${"${super}::"}{$attribute} ? *{"${super}::${attribute}"}{SCALAR} : undef;