One option is to consider an alternative inside-out system like Class::InsideOut that does not force a constructor/initialization approach on you.
package My::Singleton;
use Class::InsideOut qw( public register id );
public name => my %name;
public rank => my %rank;
my $self;
sub new {
$self ||= register( bless \(my $s), shift );
}
Note: Class::InsideOut doesn't yet support Storable singletons, but it is on the Todo list for the next couple releases.
-xdg
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
|