On Sun, 17 Sep 2000, Chris Winters wrote:

> Hi Greg,
> 
> Check out Class::Singleton for this purpose. Works great for me.
> 
> Basically, the first time you create the object, do:
> 
>  my $obj = $object_class->instance( ... );
> 
> Every successive time you want the object, just call:
> 
>  my $obj = $object_class->instance;
> 
> And you'll get the same object back. Initialization stuff (such as
> database connects, whatever) is put in the _new_instance() method,
> which is called when the object is created but not when the object is
> returned. 
> 
> The object is stored in the class itself, and Class::Singleton is
> actually a really simple module (probably a 10-to-1 ratio of
> documentation-to-code), but it's nice to have a consistent, standard
> way of doing things.

One thing C::Singleton misses is a clear_instance method though, which is
pretty much necessary for mod_perl work (I'm surprised Andy hasn't fixed
this, since he does a lot of mod_perl stuff)...

However copying the code is pretty trivial and adding that method is about
another 3 lines.

-- 
<Matt/>

Fastnet Software Ltd. High Performance Web Specialists
Providing mod_perl, XML, Sybase and Oracle solutions
Email for training and consultancy availability.
http://sergeant.org | AxKit: http://axkit.org

Reply via email to