hiding INC directories from cpan, so as to install ALL dependencies of a module in a directory - perl

I come across requirements to package a perl module with all its dependent modules, for systems where one cannot run cpan install (internet connectivity issues on production).
However, from the linux system i can do cpan install, already have these modules installed. Is there a way i can mask the #INC directories from cpan command, and provide just one directory to look for all perl modules, so that it downloads all dependencies into that local directory.
Thanks in advance!!

Take a look at lib::core::only and local::lib - the first excludes all non-core paths from #INC, the second makes it easy to set up a local perl module directory.
The combination should solve the problem.

Related

Perl cpan installed modules are installed with an individual lib path

Installing with the cpan cli tool modules - they are not found at script execution time basically as part of the #INC directories. I am using cygwin.
/home/myuser/.local/share/.cpan/build/Email-Sender-1.300031-0/lib/Email/Sender/Simple.pm
/home/myuser/.local/share/.cpan/build/Email-Simple-2.216-0/lib/Email/Simple.pm
I could now reference each single lib directory (they differ with each module installation) using the PERL5LIB Variable which is dull and boring. Am I doing something wrong? I want to install Perl Modules with cpan and use them afterwards without care where they are located...
All the module installation failed because the 'make' utility was not installed.
Now the cpan modules get installed and can be used within my scripts.

CPAN first launching configuration

I'm taking a look into Perl as a total beginner. I want to try some CPAN modules.
When I run an install command on my Osx console, CPAN asks for a configuration with the following statement :
To install modules, you need to configure a local Perl library
directory or escalate your privileges. CPAN can help you by
bootstrapping the local::lib module or by configuring itself to use
'sudo' (if available). You may also resolve this problem manually if
you need to customize your setup.
What approach do you want? (Choose 'local::lib', 'sudo' or 'manual')
What is the difference between local::lib and sudo options ?
If I understand it well, it installs some modules locally on my computer. But I don't see any difference between the two config above.
If you use sudo, CPAN will use root to install the libraries in a central location where all users on the machine can access the files without any special configuration. If you use 'local::lib', it will create a library in your home directory and install the modules such that only perl programs that have been configured to look for modules in your home directory will find the modules.
Perl uses the special variable #INC to search for module paths. So you can install modules anywhere as long as you set #INC properly before you use them. This article explains the basics.
http://www.symkat.com/find-a-perl-modules-path
You can do all kinds of fun stuff with #INC; one of my favorite hacks it to put a function pointer in there and use custom perl code to lookup modules.
Good question. When you use local::lib, you can install Modules via CPAN User specific in an given directory. Assume you choose sudo as approach, you install Modules global.
Its like installing Node.js via npm. When you install a module with npm install -g <Modul>, its global installed and you can use it everywhere. But withouth that -g flag, its just available inside your current directory.
Its about the same here, except that you choose the default way of installing CPAN Modules.

Installing Perl modules and dependencies with non-root and without CPAN

I have been writing Perl scripts for my work and the machine that I have been given to work on makes installing Perl modules difficult:
We cannot have gcc on my machine for security reasons, so I cannot use CPAN to install modules, for most modules.
I do not have access to the root account.
Usually, when I want to install a module, I put in a request and I have to wait a day or two before it gets installed. I know that nobody would have a problem with me installing them myself, so to save everyone's time and my sanity I would like to install them myself. It's just an issue of how to best do that. I have talked to various people and they said to use an RPM to install them (to get around not having gcc). However, when trying to install modules from RPMs, it does not handle the dependencies so I would manually need to handle the dependencies, which could take a while.
How can I best install Perl modules with these limitations?
On a similar machine with a similarly built Perl, install the module(s) using
mkdir ~/foo
cpan
o conf makepl_arg 'PREFIX=~/foo LIB=~/foo/lib/perl5'
o conf mbuildpl_arg '--prefix ~/foo --lib ~/foo/lib/perl5'
install Some::Module
As long as you don't do o conf commit, the configuration change will be temporary, so don't do that.
Copy ~/foo over, and set env var PERL5LIB to include the LIB directory. You can merge a newer ~/foo into an older one to add new modules.
This won't install any non-Perl libraries on which the modules depend.
See also How do I keep my own module/library directory? in section 8 of the Perl FAQ.
When you build modules, tell Perl where to install the modules.
For Makefile.PL-based distributions, use the INSTALL_BASE option when generating Makefiles:
perl Makefile.PL INSTALL_BASE=/mydir/perl
For Build.PL-based distributions, use the --install_base option:
perl Build.PL --install_base /mydir/perl
INSTALL_BASE tells these tools to put your modules into /mydir/perl/lib/perl5. See How do I add a directory to my include path (#INC) at runtime? for details on how to run your newly installed modules.
There is one caveat with INSTALL_BASE, though, since it acts differently from the PREFIX and LIB settings that older versions of ExtUtils::MakeMaker advocated. INSTALL_BASE does not support installing modules for multiple versions of Perl or different architectures under the same directory. You should consider whether you really want that and, if you do, use the older PREFIX and LIB settings. See the ExtUtils::Makemaker documentation for more details.

How to manually install XS modules?

Correct me if i'm wrong, but XS and Dynaloader based modules are those who use C/C++ shared objects (.so) and which are not PP (Pure Perl)?
Now assuming I have a machine, which does not have web-connectivity whatsoever (Solaris 10) and I want, for instance, to install Crypt::OpenSSL::AES (XS based module), copying the AES.pm file to the relevant path in #INC wont do any good since my system does not have libssl installed.
My second and most important question is, how do I install such modules when I don't have CPAN?
my approach is:
first get libssl for my platform, compile it, but where should I put that shard object file so that perl can find it?
when I have libssl installed and compiled and located where it should be, is it enough now to just copy the AES.pm to the relevant path in #INC, or do I need to configure / make it?
CPAN itself is part of the base perl install. It will always be available.
If you can't use the cpan shell to talk to the internet and fetch modules, you can at least grab the tarball from the CPAN website, put it on the target machine, untar it, then run
$ cpan .
from inside the unpacked directory. This will run the CPAN installer for that distribution. Of course if it finds missing dependencies, you'll have to fetch those yourself recursively using the same technique.
If you don't have root access I would install in ${HOME}/lib. Just make sure that the linker can find it, either the directory should be in you LD_LIBRARY_PATH environment variable, or better point EU::MM to the library and include files.
No, the module also have a part in C which has to be compiled.
To install
Download the distribution tarball: http://search.cpan.org/CPAN/authors/id/T/TT/TTAR/Crypt-OpenSSL-AES-0.02.tar.gz
Then follow the steps in the README file under INSTALLATION
perl Makefile.PL INC="-I $HOME/include" LIBS="-L $HOME/lib"
make
make test
make install
This will make sure that the module is correctly build, tested and installed.

How do I install a module and its dependencies in ActivePerl on Windows?

I want to send emails using gmail's smtp servers and perl. I am trying to install Email::Send::Gmail, but it is not clear to me what are the steps to install it. It seems that it depends on other modules that I do not have installed.
This is partially dependent on which distribution of Perl you're using.
ActivePerl includes a utility called PPM (Perl Package Manager) for installing modules. It handles dependency resolution automatically. PPM is particularly nice for installing XS modules on Windows where a compiler isn't typically available. The downside to PPM is that it some CPAN modules aren't available (probably because they fail ActiveState's automated build process). You can run PPM from either the start menu or by typing ppm at a command prompt.
A more general option is to use the interactive CPAN shell. Note that you must have a compiler to install XS modules using this method. You can access the cpan shell by typing cpan at a command prompt.
The brute-force approach of last resort is to download tarballs from CPAN and manually install them one at a time. When an install aborts due to unsatisfied dependencies download and install them then go back to the first module and try again.
Type:
cpan Email::Send::Gmail
… at the command prompt.
It's probably a good idea to set up local::lib first.
Or see the Perl Foundation Wiki on installing CPAN modules or the same but without root access.
Or see the CPAN guide to installing modules.
If you are using ActivePerl, try the PPM (Perl Package Manager) tool that comes with ActivePerl first. When you tell it to install a module, it should handle all of the dependencies for you.
Note the dependency tree for Email::Send::Gmail. Some of those modules require additional installation of third party software, most notably OpenSSL, which cpan won't do for you.
You can probably install it with:
perl -MCPAN -e shell
install Email-Send-Gmail
Hope it helps,
/Klaus
If you can, CPAN. (ha! It rhymes ... what a crime. Oops, did it again! When will this end... :p) It's essentially the way to install modules for your system. It automatically detects dependencies, downloads, installs, and tests them all for you, and backs out if ever a build or test fails. It's a fantastic and reliable way of installing modules. This works great if you're using essentially any Perl distribution besides ActiveState's distribution, including Strawberry Perl. Generally, this is done with
cpan Module::Name
or, in an interactive mode,
$ cpan
cpan > install Module::Name
If you're using ActiveState Perl, then you probably want to use ActiveState's PPM (Perl Package Manager). It's similar to CPAN, except everything comes prebuilt for ActiveState Perl. ActiveState has a document on how to use their Perl Package Manager on their website, including a graphical example.
If the easy options fail, you are not out of luck. There's some more complex, but manual methods you can do to still install the module.
Most modules that you can download will have within them a bit of metadata in a .yaml file; this will help you figure out whether or not you have all your dependencies. CPAN and PPM automatically resolve and install all your dependencies, but doing it manually will not, leaving that task up to you.
Assuming you have all your dependencies, and you need to install it manually, look for one of two files: Makefile.PL or Build.PL. If you have a Makefile.PL, cd to the directory you extraced the module within a command prompt, and type:
perl Makefile.PL
make
make test
make install
You will need a 'make' program on your system. If it's ActiveState Perl, you may need to install the module manually (see a paragraph or two down.)
If it happens to have a Build.PL, then you need to do a slightly different set of steps:
perl Build.PL
Build
Build test
Build install
(Of course, you may want to consider not installing if make/Build test fails, but that's up to you.)
As a final alternative, if your module has no xs files (ie, code that needs to be compiled on install), and all dependencies are met, you can simply move the files in the lib folder to your perl installation's site\lib folder. If you're interested in just using it for one project, you can add a PERL5LIB environmental variable, pointing to a new, custom library directory (eg, /my/project/lib) and then before running your tool, make sure the environment is set up.
As a followup, see PerlFaq8 - How do I install a module from CPAN.
Also, see PerlFaq8 - How do I keep my own module/library directory?.
Mixing installation methods is asking for heartache and headaches you don't need.
Don't use CPAN with Active Perl. Use PPM.*
PPM download sources can be found at Randy Kobes' site.
If you can't find a PPM of a module you need, you can build your own PPMs easily with Mr. Kobes make_ppm.
You can download a distribution and simply run make_ppm to build a PPM, but I prefer to do the a more "normal" build process:
perl Makefile.PL
make
make test
make_ppm
*If you install your files outside of c:/perl/site/* then it's OK to use CPAN. Just don't co-mingle CPAN shell modules with PPM modules.