Look at the order of events here. BEFORE $main::mold gets assigned a value the following calls are made:
Mold::spawn
Mold::init
Prefs::spawn
UI_Curses::spawn
Command_Interpreter::spawn
Grid::spawn
Command_Processor::spawn
Player::spawn
EventQueue::spawn
Data::Monsters::spawn
Message::spawn
So if any of those subs expect $main::mold to already have a value they would be wrong.
Im guessing that you should either alter Mold::spawn so that it says
sub spawn
{
my $this=shift or die;
my $class=ref($this) || $this;
my $self = bless {},$class;
$main::mold=$self;
$self->init()
return($self);
}
Or remove the call to init() from the constructor and change the code in main to be
$mold=Mold->spawn;
$mold->init();
Also the self references that you put in there
$self->{parent}=$self || die;
$self->{mold}=$self || die;
will cause a memory leak unless they are eventually changed.
A better design pattern for things like that is to use a pattern where the self referential structure is not itself the root object. Then the DESTORY method in the root object can safely remove the self references and the whole object will destruct when it falls out of scope.
---
demerphq
<Elian> And I do take a kind of perverse pleasure in having an OO assembly language...
|