in reply to Re: single instance shared with module
in thread single instance shared with module
you only need to return a string with the package name in a singleton's constructor.my $class = "Singleton"; $class->method();
package Singleton; my ($various, %instance, @variables); sub new { my $class = shift; # object initialization here ... *new = sub { shift } return $class; } 1;
Here we also avoid the need to check whether the object is initialized by using a glob to replace &new. None of the further calls to the constructor will execute its initial code.
All of your methods can just ignore the $self too, since there's a single instance which stores its data in file lexicals.
Makeshifts last the longest.
|
|---|