in reply to Class::Std singletons

If you want to use a singleton class with Class::Std then just don't the :ATTR hashes variables. The :ATTR is what makes the variables unique for each object. Get rid of this and then all of your variables will be shared by all the objects.

To the program the objects will still look different but there will only be one set of values.

Replies are listed 'Best First'.
Re^2: Class::Std singletons
by dstar (Scribe) on Mar 20, 2006 at 03:37 UTC
    That would work, I guess, but it's not a true singleton. Defining a class method to do it, ala:
    sub get_manager { $manager = AAPA::Manager->new(); $manager->set_galaxy(AAPA::Galaxy->new()); return $manager; }
    Doesn't work -- "Can't locate object method "get_manager" via package "AAPA::Manager" at ../AAPA/Ship.pm line 25." Fair enough, since get_manager's supposed to be a _class_ method. I just can't figure out how to tell Class::Std that...