Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Packaging Libraries before deploying my Scripts.

by ArunMKumar (Initiate)
on Oct 25, 2016 at 11:02 UTC ( [id://1174679]=perlquestion: print w/replies, xml ) Need Help??

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

Namaste Monks.. I have written a set of scripts, on a local system (my laptop) The work fine here.
Now My scripts are required to be deployed in remote system(s) and the thing I am worried about is the availability and the installation of the Libraries that I have used.
The 2 Libraries that are currently in use are "XML::LibXML" and "Spreadsheet::ParseExcel".
I have this idea where I will put them in a "lib" directory in the same project Directory, and the scripts will refer from them. My questions are as follows.
I have installed them in a directory, using the commands as follows from the extracted tar files.



perl Makefile.Pl
make
make test
make install PREFIX=<path_to_lib> LIB=<path_to_lib>


I also see the .pm files being populated in various tree structures in that lib directory.
My question now is , How do i force my scripts to reference this lib directory when It wants to look for the modules?
I am new to perl, from what I searched online I think it has to do with modifying @INC variable, while some solutions say about explicitly including these versions of the library (which I have no clue, as those post included their own perl modules).
so.. How do i force my scripts to use these libraries exclusively, and not throw an error when i deploy them to different systems (all Linux systems with perl 5 or above for sure).
  • Comment on Packaging Libraries before deploying my Scripts.

Replies are listed 'Best First'.
Re: Packaging Libraries before deploying my Scripts.
by 1nickt (Canon) on Oct 25, 2016 at 12:12 UTC

    To use a custom location for libraries, put

    use lib '/wherever/you/want';
    at the top of your script.

    As for packaging libs with your script, the approach you've outlined won't work. When you install a Perl lib via make it will be built for the system it's being built on. Some modules are simple enough that they can be picked up and moved, but most not.

    There are many ways to solve your problem, from packaging a self-contained app, to including a README with instructions on how to get missing libs. It depends on your users' ability, mostly.

    The way forward always starts with a minimal test.
      I want to clarify something here... '/wherever/you/want/' is the same as my <path_to_lib> and not any subdirectories in it..

      Regarding the secong point you mentioned, even I thought the same, I think I would create a simple bash script which will do the installation of these libraries. I will pack the tar files in the project directories as of now.

      and thanks, I will add a README.

      Appreciate the help..

        It's perhaps worth pointing out that some modules are wrappers around external libraries, e.g. XML::LibXML is an interface on libxml2. You'd need to ensure that the required libraries and so on are available on the target machines. An alternative idea worth considering would be packaging your scripts and their dependencies into an executable using something like PAR/pp, e.g. on my 64bit Debian system:

        #!/usr/bin/perl use strict; use warnings; use XML::LibXML; use Spreadsheet::ParseExcel; print "test\n";

        Packaged to an executable Packaged via:

        pp -x -o Packaged \ -l /usr/lib/x86_64-linux-gnu/libicudata.so \ -l /usr/lib/x86_64-linux-gnu/libxml2.so \ -l /usr/lib/x86_64-linux-gnu/libicuuc.so \ source.pl

        Yep. If you have some libs you made like:

        /home/fred/perl/lib/ModuleName.pm /home/fred/perl/lib/ModuleName/Extend.pm /home/fred/perl/lib/OtherModule.pm
        You only need to say:
        use lib '/home/fred/perl/lib'; use ModuleName::Extend; use OtherModule;

        The way forward always starts with a minimal test.
Re: Packaging Libraries before deploying my Scripts.
by kcott (Archbishop) on Oct 27, 2016 at 17:03 UTC

    G'day ArunMKumar,

    Welcome to the Monastery.

    "I also see the .pm files being populated in various tree structures in that lib directory."

    Some indication of those "tree structures" would've been helpful. For instance, does the module A::B::C result in

    path_to_lib/A/B/C.pm

    or something closer to

    path_to_lib/site_perl/5.24.0/.../A/B/C.pm

    Take a look at ExtUtils::MakeMaker. In particular, the "Determination of Perl Library and Installation Locations" section.

    You should probably be using PREFIX= and LIB= with perl Makefile.PL (note the uppercase 'L' at the end); not with make install. From the LIB section of "Using Attributes and Parameters":

    "LIB should only be set at perl Makefile.PL time but is allowed as a MakeMaker argument."

    — Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1174679]
Approved by Discipulus
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2024-04-23 10:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found