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

Hello,

I humbly seek guidance on the following matter,
I have recently changed from OSX to the Linux platform and found some of my scripts are giving trouble.
I had the idea that one could use perl modules by just saving them in the local directory where they would be compiled at runtime. I had even moved some of my code into an external "functions.pm" file which works perfectly.

Basically I need to know if I need to precompile perl modules I get from CPAN??

Any help is much appreciated!!

Mark

Replies are listed 'Best First'.
Re: Do I need to build perl modules??
by davido (Cardinal) on Aug 17, 2011 at 19:21 UTC

    CPAN modules should always be properly built. Just tossing essential components into a directory subverts a lot of "goings-on" that are supposed to happen upon installation. While you may be successful moving components into directories by hand, you will be missing one of the most important steps: the test suite run. Without the test suite running you have no way of being sure that you didn't miss something. Imagine an XS need that only occurs under specific circumstances. You would have to read the entire source and understand it to be sure you're not missing something that the tests could prove for you automatically.

    When a module is properly built, several things happen:

    • The manifest list is checked. This is a list that comes with the module. It ensures you've got all the components you need.
    • The module is tested with the module author's test suite. This assures that the module works on your system properly (which includes verifying that you have all needed components and dependencies). Ok, "assures" is a strong assertion, but at least "verifies that the modules passes the test suite on your system."
    • Compiles supporting XS code if necessary.
    • Creates an appropriate directory structure for the module and places it there so Perl knows where to find it.

    Other things may happen too; that's dependent on what the module's author wrote into his installation suite. But those are the basics, and aren't in exact order.

    At minimum download the module's tarball, unpack it into a temporary folder, cd into the folder, and type:

    perl Makefile.PL make make test make install

    There are some modules built with Module::Build instead, and for those, it's:

    perl Build.PL Build Build test Build install

    Nowadays people often just use cpan, CPANPLUS, or cpanm (CPAN minus) to install modules along with their dependencies for them. But occasionally you'll have to use the manual approach as described above.

    Though you can install via apt-get install any of the Perl modules your Linux (Debian/Ubuntu) distro has available to it, they will install to your system Perl, which leads me to the next topic.

    It's generally considered more trouble than worth to upgrade your system Perl independent of OS upgrades, or to bother with installing modules to system-Perl, unless you absolutely have to. People are using perlbrew to set up a local copy of Perl that is independent of the system Perl. Perlbrew makes it easy to switch between multiple installations of Perl. It will also cause your module installations to target the Perlbrew Perl installations rather than system Perl. That way you don't have to worry about installing something that interferes with how your operating system expects Perl to behave, while at the same time gaining the ability to upgrade at will, and install modules at will to this independent Perl install.

    I've got one Perl build that I use for just about everything now, and then a few alternates that I use for testing under alternate versions or configurations. Perlbrew facilitates the entire process.

    Once you've got your new Perl installation configured, you can install new modules just by typing cpan Module::Name. Then the module is fetched from CPAN, built, tested, and installed. Dependencies are handled automatically in most cases.


    Dave

Re: Do I need to build perl modules??
by pvaldes (Chaplain) on Aug 17, 2011 at 18:44 UTC

    Reloading the modules is a good idea, but please note that a lot of linux distributions have pre-compiled and packaged a lot of modules (tested for compatibility with your system). So you should always see first if your module is in the repositories. How to do this depends on the distro you have, but for instance if you have Debian (or Ubuntu) you can type something like this

    apt-cache search 'Perl module'

    You can also obtain a list of the modules installed in your system with: cpan -l

    And you most probably want to run cpan upgrade

Re: Do I need to build perl modules??
by jethro (Monsignor) on Aug 17, 2011 at 19:12 UTC

    Normally pure-perl modules can be installed simply by dropping them into an appropriate directory. Since I use normal installation procedures I don't know if there are exceptions to this. Perl modules with embedded C language parts need to be compiled with a C compiler at installation, this won't be done at execution time.

    If you want to install by hand you have to check each and every module if it is pure perl. Much easier to just use the package manager of the OS or CPAN to do that for you

Re: Do I need to build perl modules??
by shiftee (Initiate) on Aug 17, 2011 at 19:42 UTC

    Exactly the information I was looking for,
    Thanks guys!!

    Mark