in reply to Re^4: Automatic vivification of an object
in thread Automatic vivification of an object

... but if I try to create an instance of the base class as part of module compilation ...

Considering that seems to cause the problem, I'm curious as to why; what do you need that instance for?

... it doesn't work. (I suspect it has something to do with the order in which variables are declared and/or initialized.)

Tracking down the source of that problem may prove insightful!

The best thing to get people to take a look at it would be if you would provide a short, self-contained piece of example code that reproduces the problem (see http://sscce.org/).

Replies are listed 'Best First'.
Re^6: Automatic vivification of an object
by bounsy (Acolyte) on Jan 15, 2015 at 18:48 UTC

    After thinking about it some more, I believe the issue can be simplified to these three files (all in one directory):

    AAA.pm
    #!/usr/bin/perl use strict; use warnings; package AAA; our $var = 'aaa'; warn $AAA::var; warn $BBB::var; 1;
    BBB.pm
    #!/usr/bin/perl use strict; use warnings; package BBB; use base 'AAA'; our $var = 'bbb'; warn $AAA::var; warn $BBB::var; 1;
    CCC.pl
    #!/usr/bin/perl use strict; use warnings; use BBB; warn $AAA::var; warn $BBB::var;

    I have strict and warnings in each file to ensure that all possible messages get printed out. Here's the output:

    aaa at AAA.pm line 10. Use of uninitialized value $BBB::var in warn at AAA.pm line 11. Warning: something's wrong at AAA.pm line 11. aaa at BBB.pm line 12. bbb at BBB.pm line 13. aaa at CCC.pl line 8. bbb at CCC.pl line 9.

    The issue is that the code needs to have access to the value of $BBB::var from AAA (in real code this would be by reference, eval, or some other method), but that value doesn't exist until after AAA is done being compiled. Therefore, if the code that needs that access can be deferred until after compliation is complete, then the value is available for use and all would work well.