in reply to Automatic vivification of an object

And if what you want is “lazy initialization” of the instance, you can define a subroutine like this one and be sure to call it in every other method:

sub _init { my $self = shift; unless ($self->{'_initialized'}) { // Do some other stuff here maybe calling ::SUPER methods $self->{'_initialized'} = 1; // do this NOW not sooner } return $self; }

Since this method returns $self, it can be easily used “in-line” to make it unobtrusive and easy to call, for example:

sub whatever_it_is { my $self = shift -> _init; ...

As you can see, the initialization actually only takes place the first time that the function is called.   (It is significant that the flag-variable is set to True at the end of the unless block, e.g. if you are callng superclass routines and need to make sure that they do not perceive that the object is already lazy-initialized.)   (Also, I am using the common nomenclature of prefixing “internal, don’t pay attention to me” identifiers with an underscore.)

Yes, it does put a burden upon you to be sure to call the routine at the start of every other method, other than new, as illustrated, but it is unobtrusive and it works.