in reply to Re^5: Automatic vivification of an object
in thread Automatic vivification of an object
After thinking about it some more, I believe the issue can be simplified to these three files (all in one directory):
#!/usr/bin/perl use strict; use warnings; package AAA; our $var = 'aaa'; warn $AAA::var; warn $BBB::var; 1;
#!/usr/bin/perl use strict; use warnings; package BBB; use base 'AAA'; our $var = 'bbb'; warn $AAA::var; warn $BBB::var; 1;
#!/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.
|
|---|