> -----Original Message-----
> From: Tatsuhiko Miyagawa [mailto:[EMAIL PROTECTED]]
> 
> On Wed, 19 Dec 2001 16:01:22 -0000
> Matt Sergeant <[EMAIL PROTECTED]> wrote:
> 
> > Actually I was wondering about writing an Apache::Singleton 
> class, that
> > works the same as Class::Singleton, but clears the 
> singleton out on each
> > request (by using pnotes). Would anyone be interested in that?
> 
> Like this? (using register_cleanup instead of pnotes)
> 
> 
> package Apache::Singleton;
> 
> use strict;
> use vars qw($VERSION);
> $VERSION = '0.01';
> 
> use Apache;
> 
> sub instance {
>     my $class = shift;
> 
>     # get a reference to the _instance variable in the $class package
>     no strict 'refs';
>     my $instance = "$class\::_instance";
> 
>     unless (defined $$instance) {
>       $$instance = $class->_new_instance(@_);
>       Apache->request->register_cleanup(sub { undef $$instance });
>     }
> 
>     return $$instance;
> }
> 
> sub _new_instance {
>     bless {}, shift;
> }

Yeah, just like that. Why don't you wrap it up and stick it on CPAN? Saves
me another module :-)

Matt.

_____________________________________________________________________
This message has been checked for all known viruses by Star Internet
delivered through the MessageLabs Virus Scanning Service. For further
information visit http://www.star.net.uk/stats.asp or alternatively call
Star Internet for details on the Virus Scanning Service.

Reply via email to