|No such thing as a small change|
use of already eval()ed module (from string)by bliako (Vicar)
|on Jan 08, 2019 at 20:54 UTC||Need Help??|
bliako has asked for the wisdom of the Perl Monks concerning the following question:
I have come across a situation where I have a module and a test script which uses it and all is fine when done using the perl interpreter from the command line. However, when I read the module file into a string and the test script into another string with the intend to eval() the strings one after the other, the operation collapses at the eval() of the test script string.
After some time, I realised why I was getting the error Can't locate Module.pm in @INC at the second eval which indeed has a use Module; statement. Obviously Module.pm is not in @INC and any use statement for it will fail even if said module has already been eval'ed successfully.
So, I am asking whether there is an easier solution to this kind of problem than analysing each script with PPI and removing use/require statements ONLY of modules already eval'ed. Because obviously there will be some use/require statements in there which must remain as they refer to modules which should be in @INC. I am doing the PPI way right now but I hope there is a more natural way.
Here is a test which demonstrates the problem when the marked statements uncomment: