Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Yes, you can override *CORE::GLOBAL::require

by jand (Friar)
on Sep 11, 2008 at 18:36 UTC ( [id://710709]=note: print w/replies, xml ) Need Help??


in reply to Override *CORE::GLOBAL::require. Is it possible?

Yes, it is possible:
BEGIN { *CORE::GLOBAL::require = sub { my $file = shift; $file =~ s,^My/,Another/,; CORE::require($file) }; } use Data::Dumper; use My::Foo;
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.

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()).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://710709]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-03-29 07:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found