Posted on 2009-01-12 14:08:01-08 by jdhedden in response to 9699
Re: Generating thousands of objects
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.
Direct Responses: 9710 | Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.