b19f196
#!/usr/bin/perl
b19f196
use strict;
b19f196
use warnings;
b19f196
use utf8;
b19f196
b19f196
use RPM2;
b19f196
b19f196
for my $rpm_file (@ARGV) {
b19f196
    my $package = RPM2->open_package($rpm_file)
b19f196
        or die q{Could not open `} . $rpm_file . q{'.};
b19f196
b19f196
    my $package_name = $package->tag('NAME');
b19f196
    my $package_version = $package->tag('VERSION');
b19f196
b19f196
    my $module_name = $package_name;
b19f196
    $module_name =~ s/^([^-]+)-(.*)/$1($2)/;
b19f196
    $module_name =~ s/-/::/g;
b19f196
    
b19f196
    my @names = $package->tag('PROVIDENAME');
b19f196
    my @flags = $package->tag('PROVIDEFLAGS');
b19f196
    my @versions = $package->tag('PROVIDEVERSION');
b19f196
    if (!($#names == $#flags) && ($#names == $#versions)) {
b19f196
        die (q{Inconsistent number of provides names, flags, and versions in `}
b19f196
            . $rpm_file . q{'.});
b19f196
    }
b19f196
b19f196
    my $found = 0;
b19f196
    for my $name (@names) {
b19f196
        my $flag = shift @flags;
b19f196
        my $version = shift @versions;
b19f196
        if ($name eq $module_name) {
b19f196
            $found = 1;
b19f196
b19f196
            if (($flag & 0x8) && (($flag & (0x2+0x4)) == 0)) {
b19f196
                if (!($package_version eq $version)) {
b19f196
                    print $rpm_file . q{: Package version `} .
b19f196
                        $package_version . q{' differs from `} .
b19f196
                        $module_name . q{' module version `} .
b19f196
                        $version . q{'.} . "\n";
b19f196
                }
b19f196
                last;
b19f196
            } else {
b19f196
                print $rpm_file . q{: `} . $module_name .
b19f196
                    q{' in list of provides is not qualified (};
b19f196
                printf '0x%x', $flag;
b19f196
                print q{) as equaled.} . "\n";
b19f196
            }
b19f196
        }
b19f196
    }
b19f196
b19f196
    if ($found == 0) {
b19f196
        print $rpm_file . q{: missing `} . $module_name .
b19f196
            q{' in list of provides.} . "\n";
b19f196
    }
b19f196
}
b19f196
b19f196
__END__
b19f196
=encoding utf8
b19f196
b19f196
=head1 NAME
b19f196
b19f196
checkpackageversion - Check a RPM package version matches main Perl module
b19f196
version
b19f196
b19f196
=head1 SYNOPSIS
b19f196
b19f196
checkpackageversion RPM_PACKAGE...
b19f196
b19f196
It opens each RPM_PACKAGE, guesses a main Perl module from package name, finds
b19f196
it in list of provides (e.g. perl-Foo-Bar → perl(Foo::Bar) and compares
b19f196
versions. It reports any irregularities to standard output.
b19f196
b19f196
Petr Písař <ppisar@redhat.com>
b19f196
b19f196
=head1 COPYING
b19f196
b19f196
Copyright (C) 2011  Petr Písař <ppisar@redhat.com>
b19f196
b19f196
This program is free software: you can redistribute it and/or modify
b19f196
it under the terms of the GNU General Public License as published by
b19f196
the Free Software Foundation, either version 3 of the License, or
b19f196
(at your option) any later version.
b19f196
b19f196
This program is distributed in the hope that it will be useful,
b19f196
but WITHOUT ANY WARRANTY; without even the implied warranty of
b19f196
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b19f196
GNU General Public License for more details.
b19f196
b19f196
You should have received a copy of the GNU General Public License
b19f196
along with this program.  If not, see <http://www.gnu.org/licenses/>.
b19f196
b19f196
=cut
b19f196