RedHat Package Manager (RPM) and Perl Modules

cpan2rpm | Patching Modules

Various tools exist to help convert Perl modules to RPM. This page covers using cpan2rpm to convert perl modules available on the Comprehensive Perl Archive Network (CPAN) to RedHat Package Manager (RPM) files. Another option to consider: cpanspec and documentation on it.

Consult Life with CPAN for information on configuring the CPAN module so that other modules can be fed to cpan2rpm or cpanspec.

If building a custom version of perl, or installing large numbers of Perl modules, consider installing to a software depot that does not conflict with the vendor supplied version of perl. Many Perl modules are troublesome to convert to RPM, and the CPAN autobundle feature should be easier than recompiling many RPM. The local::lib module may assist in generating custom installs of modules.


The first example below shows how to build and install CGI::FormBuilder from CPAN, and the second how to build a perl script that is packaged like a module.

$ cpan2rpm --force -U CGI::FormBuilder
$ cpan2rpm --force -U --make-no-test \
--no-prfx swatch-3.1.1.tar.gz

cpan2rpm currently does not chase dependencies, which leads to manual build runs, seeing which modules the module wants, attempting to build those, and so forth. Ideally this work could be automated somehow.

The perl requirements and providing generating scripts used by RPM may need to be altered to prevent inclusion of unnecessary modules. Troublesome requires can be detected by installing newly built packages, which should fail with requirement errors. Rebuild the module using --no-requires to exclude the problematic requires. For example, to exclude CPANPLUS and XML::SAX from the install of Net::LDAP:

$ cpan2rpm -U --no-requires='perl(CPANPLUS),perl(XML::SAX::Base)' \
--no-prfx Net::LDAP

Patching Modules

Patches must be generated a directory level up from the expanded module archive, as the generated *.spec file uses the -p1 option to patch by default. -p1 strips one directory level, swatch-3.1.1 in the example below. To patch an existing *.rpm package, expand the *.src.rpm, then expand the archive under the SOURCES directory. Then, backup the files to be patched, edit them, and use the diff command to create a patch file.

$ rpm -i swatch-3.1.1-1.src.rpm
$ cd ~/src/redhat/SOURCES
$ tar xvzf swatch-3.1.1.tar.gz
$ cp swatch-3.1.1/swatch swatch-3.1.1/swatch.orig

$ diff swatch-3.1.1/swatch.orig swatch-3.1.1/swatch > swatch-bugfix.patch

Then, use the --patch option when building the module. Be sure to increment the --release option if producing a new package.

$ cpan2rpm --force --no-sign -U -i --make-no-test \
--no-prfx --patch=swatch-bugfix.patch swatch-3.1.1.tar.gz