http://qs321.pair.com?node_id=710681

cosimo has asked for the wisdom of the Perl Monks concerning the following question:

Inspired by adamk at last YAPC::Europe, I'm trying to do an "evil" experiment. I want to change the required module names on the fly. Suppose that I have:

require 'My/Module.pm'; print My::Module::foo();

Ok. Now, what I want is to add my own pragma. And if I do this, I want My::Module to be replaced with Another::Module. Something like:

use my_evil_pragma; # Here this should really load 'Another/Module.pm', # possibly using my_evil_pragma::replace_name($mod) require 'My/Module.pm'; print Another::Module::foo();

I originally tried with use, but I don't remember why I fell back on require. Anyway, it looks like I can't find a way to properly override CORE::GLOBAL::require to do what I want.

Or, is there some other way to achieve this?

... and no, it's not production code, only some experiment ...