in reply to Override *CORE::GLOBAL::require. Is it possible?
I think the important part is that the CORE::GLOBAL::require function must be imported into the namespace, not just defined. This makes some difference in how the GV entry looks, but I cannot remember why this is or was important.BEGIN { *CORE::GLOBAL::require = sub { my $file = shift; $file =~ s,^My/,Another/,; CORE::require($file) }; } use Data::Dumper; use My::Foo;
It becomes somewhat more complicated if you want to get the error messages right as well (you have to use string eval() for the CORE::require() call and prefix the call inside the string with a #line directive with information from caller()).
|
---|