Jay Buffington <[EMAIL PROTECTED]> said something to this effect on 07/06/2001:
> I'm building a web application that has a User perl module.  I
> have several other perl modules that need to know the user id
> of the current logged in user (or 0 for a guest user).  I was
> thinking that I could write the User class in such a way that
> every time (except the first) a constructor was called the same
> instance of the user object would be returned for each apache
> request.  
> 
> Is this the best way to go about solving my problem?  If so
> what's the best way to implement this?  Or maybe I should just
> pass around the user id to every class?  I'd perfer to avoid
> this if possible. 

Take a look at Class::Singleton, available on CPAN.  From the
docs:

  A Singleton describes an object class that can have only one
  instance in any system.  An example of a Singleton might be a
  print spooler or system registry. This module implements a
  Singleton class from which other classes can be derived. By
  itself, the Class::Singleton module does very little other than
  manage the instantiation of a single object. In deriving a class
  from Class::Singleton, your module will inherit the Singleton
  instantiation method and can implement whatever specific
  functionality is required.

(darren)

-- 
Unix is an operating system, OS/2 is half an operating system, Windows
is a shell, and DOS is a boot partition virus.
    -- Peter H. Coffin

Reply via email to