[Raleigh-talk] Sharing data between modules
Michael Peters
mpeters at plusthree.com
Fri Dec 19 07:25:45 PST 2008
Andrew Rankin wrote:
> I'd like to share that data between all the modules to avoid the
> multiple database connections and multiple shared library's being
> opened.
First off how are you running this? Is it under mod_perl? Some other persistant framework like
FastCGI? Or is it normal vanilla CGI?
The other question is why. Most databases should be able to handle thousands of connections without
a problem. And loading a library multiple times might not be a bad thing. It all depends on what
you're trying to do and why. If you're trying to remove bottlenecks, have you actually done any
measuring?
> Whats the best way of doing this? So far I've had suggested
> using Exporter or defining a variable using 'our' in Glovebox.pm and
> just referencing back to it.
Just to clarify things, are you worried that having "use MyModule" in lots of different places will
load different copies of that module within the same process? If so, don't worry about it. Perl will
only load 1 copy. But if your design has a single object that should be shared "globally" among the
same code in the same process then you're probably looking at a Singleton pattern, so check out
Class::Singleton.
But really, I need more information about what you're trying to do, not so much about what your code
looks like.
--
Michael Peters
Plus Three, LP
More information about the Raleigh-talk
mailing list