package YUM::Deps; use warnings; use strict; use utf8; use IPC::Run3; =encoding utf8 =head1 YUM::Deps Functions to retrieve data from YUM repositories and compute dependencies. =cut my %cache; =head1 Functions =head2 I($repo_id, $binary_dependency) Convert binary Provides $binary_dependency to base name of source package which satisfy the dependency. The data are retrived from YUM repository $repo_id. Return lists of source packages as one symbol can be provided by more packages. =cut sub provides2basenames { my ($repo_id, $provides) = @_; my @names = (); if (exists $cache{$provides}) { @names = @{$cache{$provides}}; } else { my @rpms; run3(['repoquery', "--repoid=$repo_id", '--whatprovides', $provides, '--qf', '%{SOURCERPM}'], \undef, \@rpms, undef); if ($?) { die "repoquery failed with code $?\n"; } local $_; for (@rpms) { chomp; s/(-[^-]*){2}$//; push @names, $_; } $cache{$provides} = \@names; } return @names; } =head2 I($local_rpm_file) Return package name of local RPM file $local_rpm_file. =cut sub rpmfile2basename { my $rpm_file = shift; my $name; run3(['rpm', '-q', '--qf', '%{NAME}', '-p', $rpm_file], \undef, \$name, undef); if ($?) { die "rpm failed on $rpm_file with code $?\n"; } return $name; } =head2 I($local_rpm_file) Return list of Requires of local RPM file $local_rpm_file. =cut sub rpmfile2requires { my @requires; run3(['rpm', '-q', '--requires', '-p', shift], \undef, \@requires, undef); if ($?) { die "rpm failed with code $?\n"; } chomp(@requires); return @requires; } 1;