Regarding my previous question about appending directories to @INC instead of prepending to it, I guess what I really want is for Perl to load the latest version of modules.

For deployment convenience, I ship CPAN modules with my application so that a minimum Perl installation can quickly run the application. In my application scripts I add "use lib '/path/to/bundled/cpan'". However, some of the included CPAN modules might get a bit out of date (I try to update the bundled CPAN as often as possible, but still...) and the system's CPAN module version might be newer.

What I would like is for Perl to keep searching entries in @INC and compare the versions of all modules found, and then use the latest one.

I know that doing this might open a whole can of worms (for example, the recent LWP 6.00 incompatibilities), but in general it has worked quite well so far in my case.

And I also would like to exclude this behaviour for some modules, since I also have a couple of patched CPAN modules that I want to use regardless of new version from CPAN.

Any ready-made solution I can use? Module::Load::* seems to be able to be slightly modified to do what I need, but I don't want to change all the "use" statements in my scripts/libraries. What would be ideal is probably custom hook in @INC.

Some imagined syntax:

use lib::latest "/path/to/bundled/cpan", "/another", -exclude => qr/^( +Email::Valid|LWP::protocol::)$/; # Foo::Bar should be searched in all @INC entries, and the latest vers +ion used use Foo::Bar; # the first found @INC is used, which will be in /path/to/bundled/cpan use Email::Valid;
ak

In reply to Loading the latest version of modules by Anonymous Monk

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.