Question

Quick Summary: My script changes a symlink which is used for loading Modules, and I need to load two different versions of the same module from the same location, once before things are moved, and once after things are moved.

Detailed Summary: My script changes the installed version of a program I am working on.

In a folder, I have a symlink ( '/a/b/c/parallelogram' ) which points at the installed branch of my software ( '/a/b/c/1_parallelogram' ).

My script starts with a 'use parallelogram::Const'. Then, I do some things, including making my parallelogram symlink point at '/a/b/c/2_parallelogram'.

At this point, I have a 'require 2_parallelogram/Config.pm'. The problem is that Config.pm has a 'use parallelogram::Const'. I need this to reference Const.pm in 2_parallelogram, but since I already have 1_parallelogram/Const.pm loaded, it uses that file.

I cannot change the contents of either Config.pm or Const.pm.

Is there a way for me to locally scope these 'use' statements, or to override what modules are loaded, or to unload these modules?

Any ideas appreciated!

Was it helpful?

Solution

After changing the symlink, do:

delete $INC{'parallelogram/Const.pm'};
delete $INC{'parallelogram/Config.pm'};
use Symbol 'delete_package';
delete_package('parallelogram::Const');
delete_package('parallelogram::Config');
require parallelogram::Config;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top