in reply to Howto implement versions of object instances

Hm, I had a brainstorm, but not time to test it. Please correct me if any of this wouldn't work for your mod_perl issues (or if any of my assumptions are wrong).

Perl traverses @INC in order: as soon as it finds a module that fits a require or use statement, it acts on that and stops looking. (IIRC).

So, why not do this:

use lib 'my_modules/old_version'; use lib 'my_modules/new_version'; use MyModule '2.0'; #if you need version 2.

In theory, Perl would find version 1.0 in 'my_modules/old_version', and because it doesn't match, would keep looking, finding 2.0 in 'my_modules/new_version'. If you didn't ask for version '2.0', you'd see the 1.0 version first and use that.As ikegami points out below, this approach is flawed because Perl has to find and load the module before it knows the version. However, it looks like I was heading down the right path, as his approach (inverting the order of the paths in @INC) does work. Please ++ his post if you have spare votes!

I don't really know that use $VER works exactly that way... as I said this is a brainstorm. Thoughts?

<-radiant.matrix->
A collection of thoughts and links from the minds of geeks
The Code that can be seen is not the true Code
"In any sufficiently large group of people, most are idiots" - Kaa's Law

Replies are listed 'Best First'.
Re^2: Howto implement versions of object instances
by ikegami (Patriarch) on Nov 15, 2005 at 18:03 UTC
    That doesn't work
    >type v1\AA.pm package AA; our $VERSION = 1.0; 1; >type v2\AA.pm package AA; our $VERSION = 2.0; 1; >type test.pl use lib qw( v1 v2 ); use AA 2; >perl test.pl AA version 2 required--this is only version 1 at test.pl line 4. BEGIN failed--compilation aborted at test.pl line 4.

    By the time Perl figures out the version of the module, the module has already been executed. It is therefore impossible for Perl to continue looking for other versions of the module.

    By the way, if you reverse the order of the libraries (i.e. use lib qw( v2 v1 );), version 2 will always be loaded.

      Ikegami, radiantmatrix,
      thanks for your effort. But I would stress that I need all instances of my objects in the same runtime, paralelly, without choosing of versions on lib-use-require-phase.
      Maybe I am not catching something important, but I think that your advices do not support such parallelism.