[Raleigh-talk] Sharing data between modules

Andrew Rankin andrew at eiknet.com
Fri Dec 19 07:49:27 PST 2008


Thanks for the responses guys.

Michael -

Its just normal old vanilla CGI, nothing special.  My reasoning on the
sharing of a database connection was purely cleanliness and preference
- why have multiple if I can just have one...  The database and shared
library were actually low on my list of concerns, what I really wanted
to have was the containers data shared throughout the modules since
they all used it - and if it changes one place, all modules see the
change (if that makes sense).  I was figuring if I was sharing that
data, I'd just share the other items at the same time.

Andrew


On Fri, Dec 19, 2008 at 10:25 AM, Michael Peters <mpeters at plusthree.com> wrote:
> 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
>
> _______________________________________________
> Raleigh-talk mailing list
> Raleigh-talk at pm.org
> http://mail.pm.org/mailman/listinfo/raleigh-talk
>


More information about the Raleigh-talk mailing list