The OO way would be to pass the $debug object to $cust somehow, ie $cust->setDebuggingObject($debug), this may sound like work but it pays off if you do it properly..

Another way would be just to call ::main::debug->method(args) from inside your $cust object, but this would be making the Customer object dependent upon the main having such an object, and saving it under this name. (if you later decided to change the instance of the Debug object to be called $mydebug, you'd have to change Customer as well.)

A third slightly similar way would be to have Customer call a function in main, which returns it the debug object, whenever it needs it. (In Customer) my $debugobj = ::main::getDebugObj();, but this is again dependent upon main implementing this method.. (Ok, its your main, but what if someone else used your classes?).

Fourth: (While I think of it) - Have a common Id in Customer and Debug, and keep references to the Debug objects in the Debug class. Now Customer can ask Debug directly for a specific Debug object. (it's still kinda backwards though :). my $debugobj = Debug::getDebugObj($me->debugID); (or something..)

Lastly, something like debugging can usually be done with a Singleton, ie one single object that handles debugging, instead of instanciating lots of debug objects. (Tho I guess your question was more general than that..)

C.


In reply to Re: Accessing an instantiated object from another .pm file by castaway
in thread Accessing an instantiated object from another .pm file by arc_of_descent

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.