davido has asked for the wisdom of the Perl Monks concerning the following question:
You can also insert hooks into the import facility, by putting directly Perl code into the @INC array. There are three forms of hooks: subroutine references, array references and blessed objects.
After reading the rest of the document I think I understand that the execution of the coderef held in @INC should return a filehandle to a file that is to be included, and it also looks like the rest of @INC will not be used unless the code returns undef instead of a filehandle.
Of course I've also read the examples given in the POD for require, but I guess I'm just not quite seeing it. perlvar's brief mention of the @INC and %INC hooks didn't really contribute to settling my curiosity. What is this feature for, and how is it correctly used? It seems that it must be used for runtime decisions on what files get included. Am I close to being on the right track? Can anyone provide an example of this feature at work?
Thanks for any comments!
UPDATE: I found the first mention of the @INC coderef feature in perl573delta, with the following line (in the Changes section: "21. document the coderef-in-@INC feature." That implies it's been around since before 5.7.3, but first documented in 5.7.3.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to use @INC coderef hooks
by bsb (Priest) on Jun 01, 2004 at 04:52 UTC | |
|
Re: How to use @INC coderef hooks
by Zaxo (Archbishop) on Jun 01, 2004 at 06:53 UTC | |
|
Re: How to use @INC coderef hooks
by chromatic (Archbishop) on Jun 01, 2004 at 05:28 UTC | |
|
Re: How to use @INC coderef hooks
by gmpassos (Priest) on Jun 01, 2004 at 06:13 UTC | |
|
Re: How to use @INC coderef hooks (perldoc wrong)
by LanX (Saint) on Apr 04, 2014 at 12:30 UTC |