Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: Object passing within a package

by naChoZ (Curate)
on Jan 17, 2005 at 18:20 UTC ( [id://422803]=note: print w/replies, xml ) Need Help??


in reply to Re: Object passing within a package
in thread Object passing within a package

Yes, your code is pretty much identical to what I ended up using to get past that particular problem.

Specifically, what I'm trying to write is a Curses::UI interface to a sort of psuedo-autodiscovery script. I was attempting to figure out how to pass the Curses::UI objects around without declaring full-blown globals. I'm also trying to write it in such a way that it could potentially interface with a different autodiscover script.

So essentially I have MyModule, MyModule::Interface::CLI, and MyModule::Autodiscover. I wanted to contain all the C::UI stuff in M::I::CLI, which is why I was trying to pass those C::UI objects to different subs within the M::I::CLI package. If I'm poorly reinventing a wheel, I certainly welcome input.

And yes, I do spend too much time monkeying with RT.

--
"This alcoholism thing, I think it's just clever propaganda produced by people who want you to buy more bottled water." -- pedestrianwolf

Replies are listed 'Best First'.
Re^3: Object passing within a package
by brian_d_foy (Abbot) on Jan 17, 2005 at 23:29 UTC

    Hmmm... if all things need to access the Curses::UI object, you might consider creating giving each of their objects a reference to the Curses::UI object. It should be the same object (so you don't have multiple ones), but then every time you call a method, you already have it in the object data. In that case you don't need to pass it around.

    Sometimes the Singleton design pattern can solve this little sanfu, too. There is a Perl Singletons on Perl Monks, or my article about Singletons in The Perl Review, Issue 0.1

    --
    brian d foy <bdfoy@cpan.org>

      That's great. At the time I didn't know what it was called at the time, but Kanji showed me a singleton construct one time. I just couldn't quite figure out how to apply it to what I was doing here. This was very helpful. Thanx!

      --
      "This alcoholism thing, I think it's just clever propaganda produced by people who want you to buy more bottled water." -- pedestrianwolf

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://422803]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-25 18:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found