If you were in Java I would say, load each class in a seperate sibling class loader and put any classes shared in common into a parent class loader. Java identifies classes using class loader + name, so even if two classes have the same name if you've loaded them into sibling class loaders Java won't confuse their inheritance chains and inter-class relationships.

Although Java is not Perl, and Perl is not Java, it appears you can use Perl threads in much the same way as the Java class loaders. Each thread gets its own copy of @INC and %INC. Furthermore, each thread inherits the contents of @INC and %INC from its parent thread, as illustrated in this little demo:

use strict; use warnings; use threads; use threads::shared; our @STARRING_CLASSES=qw(Carp.pm List/Util.pm Test/More.pm); my @aBig; my $aBig=bless(\@aBig,"MaybeSharable"); my $aBigShared=&share($aBig); my $t; require Carp; $t = threads->new(sub { require List::Util; print "-------------------------------------\n" , "tid=".threads->tid . " \\\%INC=".\%INC . " \\\@INC=".\@INC."\n"; while(my($k,$v)=each(%INC)) { $k="**$k" if grep{$k eq $_} @STARRING_CLASSES; print "$k=$v\n" }; print "\n"; }); $t->join(); $t = threads->new(sub { require Test::More; print "-------------------------------------\n" , "tid=".threads->tid . " \\\%INC=".\%INC . " \\\@INC=".\@INC."\n"; while(my($k,$v)=each(%INC)) { $k="**$k" if grep{$k eq $_} @STARRING_CLASSES; print "$k=$v\n" }; print "\n"; }); $t->join();

Given that, why not just use two sibling threads in your program and load one version in thread 1 and the other in thread 2?

Update: changed choice of classes to use in demo so that there is at least one package each thread loads that the other does not. (Turns out Scalar::Util pulls in List::Util, the two modules used in the original version - who knew!).


In reply to Re: Module development: concurrent versions (Updated) by ELISHEVA
in thread Module development: concurrent versions (Updated) by BrowserUk

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.