Packaging Perl CPAN modules as RPM with cpanspec
If you happen to use some CPAN module that is not already available in any repo (always check EPEL), you might consider packaging it yourself. It can really be a pain if you try to do it from scratch, that’s why you should consider using cpanspec. It’s a simple tool that will generate a specfile given a CPAN package name or package file.
First, you need to install it:
$ yum -y install cpanspec
It will also install a bunch of dependencies (mostly perl-*).
Now let’s see how it works with the Class-Generate module:
$ cpanspec --packager 'Pedro Padron <ppadron@w3p.com.br>' Class-Generate
To omit the --packager flag, just add to your ~/.rpmmacros:
%packager Your Name <you@example.com>
This will create a perl-Class-Generate.spec file in your working directory.
Name: perl-Class-Generate
Version: 1.10
Release: 1%{?dist}
Summary: Generate Perl class hierarchies
License: CHECK(GPL+ or Artistic)
Group: Development/Libraries
URL: http://search.cpan.org/dist/Class-Generate/
Source0: http://www.cpan.org/modules/by-module/Class/Class-Generate-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildArch: noarch
BuildRequires: perl(ExtUtils::MakeMaker)
Requires: perl(:MODULE_COMPAT_%(eval "`%{__perl} -V:version`"; echo $version))
%description
The Class::Generate package exports functions that take as arguments a
class specification and create from these specifications a Perl 5 class.
The specification language allows many object-oriented constructs: typed
members, inheritance, private members, required members, default values,
object methods, class methods, class variables, and more.
%prep
%setup -q -n Class-Generate-%{version}
%build
%{__perl} Makefile.PL INSTALLDIRS=vendor
make %{?_smp_mflags}
%install
rm -rf $RPM_BUILD_ROOT
make pure_install PERL_INSTALL_ROOT=$RPM_BUILD_ROOT
find $RPM_BUILD_ROOT -type f -name .packlist -exec rm -f {} \;
find $RPM_BUILD_ROOT -depth -type d -exec rmdir {} 2>/dev/null \;
%{_fixperms} $RPM_BUILD_ROOT/*
%check
make test
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root,-)
%doc Changes README
%{perl_vendorlib}/*
%{_mandir}/man3/*
%changelog
* Wed Feb 17 2010 Pedro Padron <ppadron@w3p.com.br> 1.10-1
- Specfile autogenerated by cpanspec 1.78.
Note that cpanspec detects the module’s buildsystem (Makefile.pl or Build.pl) and creates the %build, %install and %check sections accordingly. It also adds perl(ExtUtils::MakeMaker) or perl(Module::Build) as BuildRequires.
Although not recommended, you can also ask cpanspec to build the SRPM or the RPM itself:
$ cpanspec --build Class-Generate
The reason why this is not encouraged is because you should always check the resulting specfile for errors or inconsistences. In this case, cpanspec could not detect the package’s license, so it makes a guess and asks you to double-check it:
License: CHECK(GPL+ or Artistic)
That’s what rpmlint will complain about when checking the SRPM:
$ rpmlint perl-Class-Generate-1.10-1.fc12.src.rpm perl-Class-Generate.src: W: invalid-license CHECK 1 packages and 0 specfiles checked; 0 errors, 1 warnings.
Another quite common issue is when RPM’s dependency generator doesn’t detect correctly your Provides and Requires.
You can check the list of Provides and Requires with:
$ rpm -qp --provides <package_file> $ rpm -qp --requires <package_file>
If you notice something is missing, you can use the --add-provides or --add-requires flags (there is also --add-buildrequires). If you want to remove something, use --filter-requires and --filter-provides.
It is worth mentioning that cpanspec filtering options will add a shell script file to your package which will be responsible for filtering the dependency generator output. It is also possible to do it in the %prep section, without requiring additional files. You can find more info about it here.
To find out about other cpanspec options, just take a look at the man page.
So, if you decide you want to maintain your own CPAN module RPM, here are a few tips:
- use cpanspec
- review your specfile
- check your specfile and SRPM with rpmlint
- read Fedora Packaging Guidelines
- read Fedora Package Review Guidelines
- read Fedora Packaging Guidelines for Perl
- read Fedora Packacking Tips for Perl
- contribute if possible





Eaeeeeee jovem!!!!!