Posted by Steve on Wed 12 Jan 2005 at 17:34
Perl is a very widely used language which gets a lot of its power from the huge number of third party modules which available in the CPAN archive. If you want to use a perl module which hasn't been packaged for Debian you have a choice to make.
Your options are to build a Debian package yourself, or install the module "by hand", independent of the Debian packaging system.
The former is the option which I usually chosen, as it makes it simple to install the produced package on multiple machines.
(Another advantage of making Debian packages of perl modules which aren't yet available is that they'll be upgraded automatically if they are ever included in Debian in the future).
Creating simple Debian packages of perl modules is greatly simplified by the dh-make-perl package.
Install it like this:
apt-get install dh-make-perl
As an example of a module which isn't available in Debian's archive is HTML::Template::JIT - which is a handy module for caching template files, the kind of files which are used to run this very website!
If we wanted to install that using CPAN, the perl module which builds and installs modules we'd run:
perl -MCPAN -e 'shell' install HTML::Template::JIT
Instead of that we want to build a Debian package - which we can do as follows.
First of all we download the source to the module, and unpack it:
wget http://search.cpan.org/CPAN/authors/id/S/SA/SAMTREGAR/HTML-Template-JIT-0.04.tar.gz tar -pzxvf HTML-Template-JIT-0.04.tar.gz
Once this is done we can run the dh-make-perl command to setup a simple set of packing files, inside the module source directory.
dh-make-perl HTML-Template-JIT-0.04/
This will produce a subdirectory called debian/ which has the rules to build, install, and handle the package. Feel free to browse around in there - all of the files are documented in the Debian New Maintainer's Guide.
As defaults for a module you wish for personal use only the generated files will likely be all you need. For producing a module you wish to upload to the Debian repositories though you will need to do much more work on them, after reading the Debian Perl Policy.
Anyway, back to our module. Once the dh-make-perl command has been executed you can build the module for real:
cd HTML-Template-JIT-0.04 debuild
Once this has finished executing you should have a .deb file sat waiting for you:
skx@lappy:~/HTML-Template-JIT-0.04$ cd .. skx@lappy:~$ ls *.deb libhtml-template-jit-perl_0.04-1_all.deb
This module can be installed with "dpkg --install", or uploaded to your own apt repository.
When you have a new release you can go through the same steps to build a new package, which can be upgraded.
The only downside to this method of producing packages is that the dependencies will be weakened - here we've produced a package HTML::Template::JIT, now realistically this package is useless without HTML::Template (contained in the libhtml-template-perl package) but that isn't mentioned as a package dependency.
If you're keeping track of such things you should be OK, otherwise you might find unexpected breakages.
This article can be found online at the Debian Administration website at the following bookmarkable URL:
This article is copyright 2005 Steve - please ask for permission to republish or translate.