Well, I worked on this a bit, and have come to the conclusion that there is no way to deal with this on a general basis. For example, what happens if you instantiate a singleton class, and then try to instantiate a child class that inherits from it. There is no way for the same object to represent (i.e., be blessed into) two classes at the same time.
Generic singletons are easy. When you try to deal with inheritance, the problem becomes intractable. My conclusion is that these sort of nuances need to be handled by the developer.
In any case, the simplest singleton skeleton using Object::InsideOut would look something like this:
package My::Class; {
use Object::InsideOut;
my $singleton;
if ($threads::shared::threads_shared) {
share($singleton);
}
sub new
{
my $thing = shift;
if (! $singleton) {
$singleton = $thing->Object::InsideOut::new(@_);
}
return ($singleton);
}
}