perl5ever has asked for the wisdom of the Perl Monks concerning the following question:

Does anyone know of any perl modules which will not work if they are copied from their original install directory to another directory and used from the new directory?

Example: I install module M with Makefile.PL PREFIX=/some/dir. I then cp -r /some/dir /someother/dir.

Can I always expect PERL5LIB=/someother/dir/lib/perl5 perl -MM to work?

Replies are listed 'Best First'.
Re: are installed modules relocatable?
by ikegami (Patriarch) on Nov 08, 2010 at 22:52 UTC
    Relocating perl itself won't work, but relocating modules should. After all, that's how ppm works. Specifically, it copes the blib/ dir that gets created when the module is built.
      would it still work if you moved say Mechanize.pm to another directory and then tried to use www::mechanize?
      the hardest line to type correctly is: stty erase ^H
        If you're now asking about WWW::Mechanize specifically, you can easily answer that yourself.
Re: are installed modules relocatable?
by bart (Canon) on Nov 09, 2010 at 12:27 UTC

    Relocating modules ought to work, as long as the files stay in accessible through @INC. That is how PPM, the module installer from ActiveState, works: the prebuilt files, including binaries, are stuffed into a .tar.gz file are de-archived into their final location, by PPM.

    Another data point: CPAN modules are tested first in the place where they are built, and install merely copies them over to their final location.

    I don't quite understand your question about PERL5LIB... but it definitely won't work if perl runs in taint mode. In that case PERL5LIB is simply ignored. On the other hand: yes, the same format will work regardless of where you move the module to, though I wouldn't be to sure if you move it to another machine...

Re: are installed modules relocatable?
by zentara (Cardinal) on Nov 09, 2010 at 12:52 UTC
    No one mentioned it yet, but if a module has an xs (c compiled) component, just moving the module itself will probably fail, unless the associated blib is moved also, and that can be tricky.

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
Re: are installed modules relocatable?
by locked_user sundialsvc4 (Abbot) on Nov 09, 2010 at 13:42 UTC

    I advise you to change the destination location by making appropriate cpan configuration changes, then re-install the modules.   In this way, you allow the installers (and self-test scripts) to “do what they ordinarily do for you, in the usual way.”

    This bypasses many potential problems, while incurring only a modest (one-time) cost in time.   Since the code will be installed and self-tested by this process, and because it will install only if all the self-tests pass, it becomes a foundation you can reasonably stand on without worrying (too much) about falling into the river.

    (I’m not concerned with how long it takes to build the bridge.   The thing that I earnestly want to avoid is the river.)

    When I am, for example, “deploying a server or a web site,” I actually build an installation-script, set up a little “sandbox” somewhere, launch the script and sit back to watch it go.   I want that script to run clean, start to finish, leaving behind a fully configured module library.   If it doesn’t, I fix the script, tear down the entire sandbox (as in: rm -rf sandbox_dir), and try again (and again...) until it works.   So now, the deployed server configuration actually has a completely-repeatable installer.   There are, of course, tools to assist with that process.