Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Loading the latest version of modules

by Anonymous Monk
on Jul 06, 2011 at 02:27 UTC ( #912902=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

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;

Replies are listed 'Best First'.
Re: Loading the latest version of modules
by AnomalousMonk (Chancellor) on Jul 06, 2011 at 02:44 UTC
    What would be ideal is probably custom hook in @INC.

    Don't know if this will help you, but that sentence triggered the memory of (see perlvar):

    You can also insert hooks into the file inclusion system by putting Perl code directly into @INC. Those hooks may be subroutine references, array references or blessed objects. See "require" in perlfunc for details.
      Yep, I was hoping someone already wrote the hook code :)
Re: Loading the latest version of modules
by creamygoodness (Curate) on Jul 06, 2011 at 04:40 UTC

    It's hopeless. Give up.

    Module versioning in interpreted languages can't be solved until the version number becomes part of the package identifier:

    use aliased Foo3 => 'Foo';

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://912902]
Approved by planetscape
[Corion]: Meh. I need to find myself a better "programming" feed than r/programming (which is just HackerNews reposts and advertisements, very little code). Maybe I should select a list of links that I liked on r/programming and then google for ...
[Corion]: ... an aggregator site that also listed (ideally) all of these links once. And maybe also have an exclude list to blacklist some of the most spammy links that the site may have never mentioned at all
[marto]: I gave up reading HN at all, and feel much better for it :P
[Corion]: Now, how to best automate that Google search ... :-)
[Corion]: marto: Yeah, I'm also short of not reading it at all. I already stopped reading it in the morning because it gave me a foul mood.
[Corion]: The good posts on HN are the non-computing posts. Most of the other stuff is maybe relevant to you if you are 20 and live in Silicon Valley...
[Corion]: Two attributes that don't describe me.
[Corion]: Maybe I should also write a curator for HN or simply not read it anymore, like you do.

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2017-07-24 13:24 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (354 votes). Check out past polls.