perl.prov in RPM 3.0.5 for AIX is broken

Posting to hopefully help the next person googling this issue. The perl.prov script in RPM 3.0.5 [r51] from the AIX Toolbox for Linux is horribly broken. It fails under the following circumstances:

  • If a Perl module has improperly-terminated POD, it will skip over valid definitions. This can start in one file and spill over due to the global nature of the binary flip-flop operator.
  • If a Perl module does this:
    text package Foo; $VERSION = 1.2.3; .. .. later .. .. package Bar; .. .. later .. .. package Foo; ..


    it loses the version number.
  • If a Perl module uses C<our> or a fully-qualified package variable name (e.g. $Foo::Bar::VERSION) to define the version number, it will not detect it.
  • If a Perl module defines the special $RPM_Provides variable, it fails due to a typo (C<spit> should be C<split>).

Furthermore, RPM will not invoke find-provides.perl (an sh wrapper around perl.prov) automatically; %__find_provides needs to be manually overridden in the SPEC file.

I've attached a minimal unified diff to perl.prov to resolve these issues. Apply with GNU patch. Additionally, here is a global macro you can define to automatically call find-provides.perl instead of find-provides if "perl" is in the package name:

%__find_provides /opt/freeware/lib/rpm/find-provides%{expand:%%( \
  if [[ %{name} = *[Pp][Ee][Rr][Ll]* ]] ; then echo .perl ; fi)}

If you don't have root or aren't willing to directly patch the script, you will need to copy find-requires.perl and perl.prov out of /opt/freeware/lib/rpm and modify the macro and find-requires.perl to reflect the new location. There are some issues with find-requires.perl as well (for starters, AIX xargs doesn't take the -r flag), but we're using cpanspec, which computes the BuildRequires and Requires lines from CPAN, so it's not such a big deal.

I should add that this patch doesn't make perl.prov bulletproof. There are still some situations where improperly terminated POD or weird package/version definitions (e.g. a newline between the package keyword and the package name) can trip it up. Perl is tricky to parse in general and a lot of maintainers have struggled with this particular problem.