One use is to observe the dependency graph of your codebase. You can do some things with an @INC hook that you can't do by overloading CORE::GLOBAL::require.

One of the things you can do with an @INC hook is signal the interpreter to keep looking for a file on disk, or fake out that you've got a module that you don't really have.

I've found that most of the time I want my @INC hooks to live at $INC[0] or at $INC-1, depending on whether I'm writing an observer or a fallback hook. Simply unshifting (or pushing) your hook where you want it isn't sufficient, since other modules you load can and will tamper with the ordering of things in @INC. "use lib", for example, will push to @INC, and if your hook depends on being the last most entry in @INC, then now you're broken. Tieing @INC is the only way I've found to ensure my hooks stay where I think they belong.

I wrote Array::Sticky::INC to ensure @INC hooks stay where they belong; you might have a look at that module, and some of the documentation I wrote up as part of it, for a bit more detail and use cases.


In reply to Re: Use cases for hooks in @INC? by belden
in thread Use cases for hooks in @INC? by LanX

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.