At 00:33 -0800 2001.12.12, David Iberri wrote: >Can anyone point me to some docs relevant to multiple inheritance?
Damian Conway has some good info on it in his book. Also of interest is his new NEXT module which makes multiple inheritance ... better. http://use.perl.org/article.pl?sid=01/12/05/1654222 NEXT is included with perl 5.8.0 and MacPerl 5.6.1, and is on the CPAN. >My problem is that I need the data for class C to inherit the data from >classes A and B in addition to their methods. This implies that C's >constructor will have to call the constructors for A and B and then somehow >merge the data together (without depending on how objects of class A and B >are represented, e.g., as array or hash references). I've read over >perltootc and the docs for Class::Object::Inheritable, but things are still >unclear. As it turns out, NEXT is pretty good at this. Here's how I might do it: package A; use NEXT; sub new { my $self = shift; $self = bless {}, $self unless ref $self; my %data = ( _key1 => 'val1', _key2 => 'val2' ); @{$self}{keys %data} = values %data; $self->NEXT::new(@_); return $self; } package B; use NEXT; sub new { my $self = shift; $self = bless {}, $self unless ref $self; my %data = ( _key3 => 'val3', _key4 => 'val4' ); @{$self}{keys %data} = values %data; $self->NEXT::new(@_); return $self; } package C; use base qw(A B); use NEXT; sub new { my $self = shift; $self = bless {}, $self unless ref $self; my %data = ( @_ ); @{$self}{keys %data} = values %data; $self->NEXT::new(@_); return $self; } You could do it with SUPER too, but that can get messier in MI. The point is, though, that with new() you need to be careful to be able to accept either a class or an object as the first parameter, so you can call them as object methods from the original new(). HTH, -- Chris Nandor [EMAIL PROTECTED] http://pudge.net/ Open Source Development Network [EMAIL PROTECTED] http://osdn.com/