[Blogged about it here: http://netmesh.info/jernst/Technical/perl-
inheritance-problem.html ]
There are three very simple classes in the following code: C is a
subclass of B, which is a subclass of A.
If I try to instantiate B (see last two lines of the code below), I'm
getting this output:
Point B: Exporter
Can't locate object method "new" via package "B" at madness.pl
line 23.
However, if I comment out class C (which isn't even instantiated by
my code!) it works!
It also works if I rename class B to Z, for example. And where in the
world would class Exporter suddenly come from? (see debugging output
of the @ISA)
Why would it do such a thing? Help!
Here is the code: (download from http://netmesh.info/jernst-files/
madness.txt )
#!/usr/bin/perl
package A;
use fields qw(a1 a2);
sub new {
my $self = shift;
$self = fields::new( $self ) unless( ref( $self ));
print "Point A: " . join( ", ", @ISA ) . "\n";
$self->{a1} = 'value of a1';
print "Setting value of a1\n";
return $self;
}
package B;
use base qw( A );
use fields qw(b1 b2);
sub new {
my $self = shift;
$self = fields::new( $self ) unless( ref( $self ));
print "Point B: " . join( ", ", @ISA ) . "\n";
$self->SUPER::new();
return $self;
}
package C;
use base qw( B );
use fields qw(c1 c2);
sub new {
my $self = shift;
$self = fields::new( $self ) unless( ref( $self ));
print "Point C: " . join( ", ", @ISA ) . "\n";
$self->SUPER::new();
return $self;
}
package Main;
my $obj = new B();
print "obj is $obj\n";
I tried this on v5.8.6 (OSX), v5.8.3 (Suse), and v5.8.0 (Red Hat);
same results.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>