The POD contains a simplistic scheme for a
singleton class. As written, its main deficiency is
that the singleton object isn't reinitialized if the "new"
method is called with different parameters.
If the class is truly singleton in the way you described,
you could override _ID with your own
:ID subroutine:
sub _id :ID { return 0; }
Be aware that you must guarantee that object destruction
occurs before you create another object of such a class.
Otherwise, destruction of the old object will wipe out the
data of the new object.
Customizing the "new" method for each class based on its
needs is a nice idea. Thanks. I'll look into it, but it
will take some work.
|