Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Loading the latest version of modules

by Anonymous Monk
on Jul 06, 2011 at 02:27 UTC ( [id://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 (Archbishop) 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
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://912902]
Approved by planetscape
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (8)
As of 2024-05-28 14:13 GMT
Find Nodes?
    Voting Booth?

    No recent polls found