Only doesn't seem to work anymore. (at least not on 10.10 which is the version we're still on.

It's been a while since I've played with carton, but having to use carton exec to start the software is less than ideal imo, and I'm still not sure that it allows for the same application to be running multiple versions of a package. Picking a particular version of a library is pretty straight forward, it's running multiple at the same time that stumps me. Here's some code I put together to pick a particular version:

package LoadModule; use strict; use warnings; my $wantedPackages; my $INC_LOADED; sub import { my $pkg = shift; my ($module, $version) = @_; $wantedPackages->{$module} = $version; push(@INC, \&loadLib) unless($INC_LOADED); $INC_LOADED = 1; } sub loadLib { my ($codeRef, $filename) = @_; my $moduleName = $filename; # Strip the implied pm $moduleName =~ s/\.pm$//; if(exists $wantedPackages->{$moduleName}) { my $package = $moduleName . "-" . $wantedPackages->{$moduleNam +e} . ".pm"; if(-e "./lib/$package") { my $fh; open($fh, "<", "./lib/$package") || die "Can't open ./lib/ +$package: $!"; return($fh); } } else { return undef; } } 1;
Below is how loadModule is used
package TestModule1; use LoadModule MyLib => 'v1'; use MyLib; sub doPrint { MyLib::foo(); } 1;

In the example above I have

lib/MyLib-v1.pm and lib/MyLib-v2.pm
Both with slightly different behavior but with the same overall code.

Tihs works great for the first module loaded. However, if I load other version of the same module they don't seem to get loaded (I suspect there's namespace collision).


In reply to Re^2: Multiple package versions (use only modules cpanfile pinto carton local::lib install_base)) by amw1
in thread Multiple package versions by amw1

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.