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

Alright, so I have been given some legacy code by my manager and asked to make it portable. It needs to be such that as long as the machine it is copied to has a base perl 5 install it will run without modification.

My first step was to move the modules to a local library and to use "use lib ..." to set the path.

I ran into a problem though in that one of the modules used is dependent on another module.

My next step was to use a UNIX shell script to set the PERL5LIB environment variable. This didn't work either.

I am now unsure of what to do. Any help would be greatly appreciated.

Replies are listed 'Best First'.
Re: Dependencies of Dependencies
by BerntB (Deacon) on Oct 14, 2009 at 23:12 UTC

    Have you seen PAR? (See e.g. tutorial linked from par.perl.org.) It is a neat distribution tool which pack up a script with all its module dependencies, etc.

    I am not that familiar with PAR myself, so I won't give you problems by trying to help you with it... :-)

      That is a possibility, but I think my higher ups would prefer the scripts in a very visible format. I'll do this is I have to but I would prefer some other solution.

      Thank you very much though, it definitly IS a possibility.

Re: Dependencies of Dependencies
by moritz (Cardinal) on Oct 14, 2009 at 21:00 UTC

    Why not just put the module into the same directories where the other modules live, and are found by use lib?

    Perl 6 - links to (nearly) everything that is Perl 6.
      Hmmm ,

      Methinx the OP already thought of that - My first step was to move the modules to a local library and to use "use lib ..." to set the path..

      It sounds to me like the OP has some legacy code with an incumbent degree of circularity - so I suspect a refactoring may be the order of the day.

      A user level that continues to overstate my experience :-))
        I have a hard time imagining a case where a circular dependency would be a problem if the module is installed locally, but would not be a problem if installed system wide.

        Except maybe when there are multiple modules installed, and one messes with %INC and @INC at compile time, breaking the circularity by loading a different module - but surely Melasoul would have mentioned such black magic?

        There might be other problems though of which I haven't thought at first: If the installation is to work with any version of perl 5, and relies on some modules that are now in core, but weren't at the release of perl-5.0.0, then Melasoul would have to include some modules which are compatible all the way back to perl-5.0.0, but shadow a core module in 5.10.1, and still provide the same functionality.

        Frankly that seems next to impossible to me, and opens up the question if the requirements are really as tight as originally described. Or if it might be a better solution to provide a virtual machine with a uniform perl installation than trying to adopt to any possibly perl 5 installation.

        Or maybe it's just too late in my timezone, and I'm imagining things... best to wait for feedback from the OP.

        Perl 6 - links to (nearly) everything that is Perl 6.
Re: Dependencies of Dependencies
by Melasoul (Novice) on Oct 15, 2009 at 11:52 UTC

    Thanks everyone for the help.

    To clarify a bit. Right now my specific problem is with Parse::CSV requiring Text::CSV_XS.

    They are both in my lib folder and both are used for various reasons in the script. However, Parse::CSV is dependent on Text::CSV_XS. I added the path to my lib folder in the various ways described in the original post.

    As said before, the uses of Text::CSV_XS by the scripts are fine, but when Parse::CSV is called it tells me it can't find Text::CSV_XS.

      Please try to be more specific - what's the full error message? In which path is CSV_XS.pm?

      Since it's an CS module, it also needs to find its C libraries. Did you just copy that? You might have to actually install it into the directory where you want it to be.

      Perl 6 - links to (nearly) everything that is Perl 6.

        Sorry.

        This is my file tree:
        (local)lib
        +auto
        |+Parse
        ||+CSV
        |||+.packlist
        |+Text
        ||+CSV_XS
        |||+.packlist
        |||+CSV_XS.bs
        |||+CSV_XS.dll
        |||+libCSV_XS.dll.a
        +Parse
        |+CSV.pm
        +Text
        |+CSV_XS.pm

        The error is: Can't locate loadable object for module Text::CSV_XS in @INC...