2022 twenty-four merry days of Perl Feed

Lapland Packaging Department - Part 1

Compiling Perl modules manually from source downloaded from CPAN - 2022-12-20

Once upon a time in the far North in Lapland (more precisely in Korvatunturi), Tonttu the nisse joined the Lapland Packaging Department after a successful series of interviews with Joulupukki -- aka Santa -- himself. Tonntu got the challenging task to make the Packaging Department's work more effective. On his very first day in the middle of November he was checking the IT infrastructure in the warehouse. He noticed the network is segmented and only one machine had connection to the internet through a proxy.

There was not much time left until Advent so he decided to stick with Perl, his favourite programming language.

"Perl is capable of everything by itself, anyway", he thought.

Unfortunately there was no chance to use tools like cpan or App::cpanminus only on that single machine connected to the internet. And that connection worked only when the http_proxy and https_proxy were explicitly set beforehand.

First of all he needed a solution to be able to use at least a handful of modules to accomplish his work.

"Why not compile the required modules from source downloaded from CPAN?", he asked himself.

It sounded like a good starting point. He immediately made his hands dirty.

Tonttu quickly jotted down a small how-to:

This method can be used to compile any Perl module manually on Linux!

First of all make sure, that PERL5LIB is loaded. If not, load it with export PERL5LIB=/path/to/your/perl (especially if you have Perl installed to a custom location).

$ echo $PERL5LIB
/home/cabox/perl5/lib/perl5

If the output is empty, that means PERL5LIB is not loaded (most probably Perl is installed into a custom location). So let's load it:

export PERL5LIB=/path/to/your/perl

Second, we need to download the module from CPAN. Let's demonstrate the process with Pod::Advent:

Download the tarball for the installation:

$ wget https://cpan.metacpan.org/authors/id/D/DA/DAVIDRW/Pod-Advent-0.24.tar.gz

Untar the archive:

tar -xzvf Pod-Advent-0.24.tar.gz

Switch to the directory of the module's source:

$ cd Pod-Advent-0.24

Execute Makefile.PL with Perl.

$ perl Makefile.PL
Checking if your kit is complete...
Looks good
Generating a Unix-style Makefile
Writing Makefile for Pod::Advent
Writing MYMETA.yml and MYMETA.json

Then execute make and make install.

$ make
cp lib/Pod/Advent.pm blib/lib/Pod/Advent.pm
cp bin/pod2advent blib/script/pod2advent
"/home/cabox/perl5/perlbrew/perls/perl-5.28.0/bin/perl" -MExtUtils::MY -e 'MY->fixin(shift)' -- blib/script/pod2advent
Manifying 1 pod document
Manifying 1 pod document

$ make install
Manifying 1 pod document
Manifying 1 pod document
Appending installation info to /home/cabox/perl5/lib/perl5/x86_64-linux/perllocal.pod

In the case of a more complicated module, tests might fail. You might be presented with errors in the output, or in the worst case, you might face dependency hell. DISCLAIMER: To avoid dependency hell or other errors upon module installation it is recommended to use cpan or cpanm wherever and whenever possible.

Tonttu knew that installing modules this way is cumbersome, but sometimes, in difficult environments, these steps can come handy.

Santa took a look at the how-to and told Tonttu kindly: "Not bad, especially on your first day, but I am sure you are able to improve it. Try to think about extending the solution."

Tonttu went to the community room and started knitting -- that was his favorite hobby and it helped him to think.

After finishing a scarf with red nosed reindeers, the solution was already in his head. Tomorrow he will try it out, but that is already another story.

Gravatar Image This article contributed by: Csaba Simándi <x1m4nd1@gmail.com>