First things first

> > "Why do you even need a hook if your require happens right away?"

a require is basically a

instead of a hook you can simply eval your template and update %INC.

> I don't need to write individual X/Y/Z.pm modules for require X::Y::Z statements.

you don't need to save them to a file.

Just eval the code and update %INC

> > "Why are you installing multiple hooks?"

A hook is an abstraction of a directory path in @INC, which are searched sequentially.

Either a path includes a requested module (SUCCESS) or the next is searched (FAIL)

But your hook in the OP always returned the same code of the first module, no matter which module was requested. It should have signaled a FAIL, to allow the next path/hook to handle the request.

And each of your hooks is only returning one file, which is an overkill and "littering" @INC with hooks.

> Perhaps you would share your understanding.

If you want you can look into the working example I wrote for HaukeX' webperl project:

[WEBPERL] dynamically importing non-bundled modules via http

you just have to adapt the coderef $fetch and %INC_FETCH to your needs.

BUT as I said, you don't even need hooks if you eval those modules right away.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery


In reply to Re^3: require() @INC hooks problem by LanX
in thread require() @INC hooks problem by kcott

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.