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...

In reply to Re: Re: globalization sorrows by demerphq
in thread globalization sorrows by vaevictus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.