Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^5: Overriding the built-in require function (@INC)

by lodin (Hermit)
on Feb 06, 2008 at 23:46 UTC ( [id://666700]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Overriding the built-in require function (@INC)
in thread Overriding the built-in require function

Modifying the @INC to include a code ref wouldn't allow for this - you merely return the code (via a filehandle), but at this point, it hasn't been compiled, so you can't interact with it yet.

Oh, but you can :-). You just have to do a bit of work. I just recently described this in Re^3: Notification on module load, and redefinition of module methods.. Enjoy!

lodin

  • Comment on Re^5: Overriding the built-in require function (@INC)

Replies are listed 'Best First'.
Re^6: Overriding the built-in require function (@INC)
by Tanktalus (Canon) on Feb 07, 2008 at 00:08 UTC

    I'm pretty sure that that node would constitute Cruel and Unusual Punishment for the perl interpreter ... nevermind any maintenance personnel that has to try to decipher it six months from now... :-)

    *boggle*

    (Oh, and ++thanks for pointing out how to do that.)

Re^6: Overriding the built-in require function (@INC)
by /dev/urandom (Beadle) on Feb 07, 2008 at 21:09 UTC
    The OP was correct, my intention from the start was to manipulate the loaded module before anything else could use it.

    Anyway, I tried to do something similar, before I posted the initial question. Basically, in the @INC callback, it would remove itself from the @INC, use require to load the module in question, the put itself back in the @INC. The only problem was, that I had to somehow return a valid filehandle, otherwise, perl would continue down the @INC, and still load the module, even though I've loaded it beforehand, thus, overwriting my changes. The filehandle proved to be the most difficult task, since I had to return a filehandle to a valid file, yet, upon read, I'd have to just return '1;' as code, so as not to overwrite my changes. And I gave up at that point :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-25 18:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found