Hi,
I have a question regarding a set of modules that subclass each other, and I
hope it is appropriate for this group.
Here is a test program (with no use strict and warnings for beeing concise):
# program.pl:
#!/usr/bin/perl
use Third;
Third->new->run;
# Third.pm:
package Third;
use parent 'Second';
sub run {print "Third\n";}
1;
# Second.pm:
package Second;
use parent 'First';
sub new {
my $class = shift;
my $self = $class->SUPER::new;
#bless $self;
return $self;
}
1;
# First.pm:
package First;
sub new {
my $class = shift;
return bless {}, $class;
}
sub run {print "First\n";}
1;
The program works fine and prints "Third" if I comment the line
#bless $self;
from Second.pm.
But if I uncomment it, the program prints "First" which is not correct.
I know that if I re-bless the object in the Second.pm it becomes a "Second"
class but I don't know why the Third.pm module can't use its own run() method,
because it still subclasses Second and run() from Third should override any
other run() which was defined previously. (or not?)
I have read that re-blessing should be usually avoided because it can create
problems, but I couldn't find an explanation for this kind of issues.
Thanks.
--
Octavian
__________ Information from ESET NOD32 Antivirus, version of virus signature
database 5345 (20100805) __________
The message was checked by ESET NOD32 Antivirus.
http://www.eset.com