summaryrefslogtreecommitdiffstats
path: root/lib/App
diff options
context:
space:
mode:
Diffstat (limited to 'lib/App')
-rw-r--r--lib/App/ArchLinux/PackagerTools.pm4
-rw-r--r--lib/App/ArchLinux/PackagerTools/Pacman.pm68
2 files changed, 69 insertions, 3 deletions
diff --git a/lib/App/ArchLinux/PackagerTools.pm b/lib/App/ArchLinux/PackagerTools.pm
index 0a45bb8..cfc2f01 100644
--- a/lib/App/ArchLinux/PackagerTools.pm
+++ b/lib/App/ArchLinux/PackagerTools.pm
@@ -80,8 +80,10 @@ older) and the CPAN distribution.
method get_updateable_packages($distribution_names) {
my @packages;
+ my $repo_versions = $self->{deps}->{pacman}->get_perl_distribution_versions($distribution_names);
for my $dist_name ($distribution_names->@*) {
- my $repo_version = $self->{deps}->{pacman}->get_perl_distribution_version($dist_name);
+ #my $repo_version = $self->{deps}->{pacman}->get_perl_distribution_version($dist_name);
+ my $repo_version = $repo_versions->{$dist_name};
my $dist = $self->{deps}->{cpan}->get_dist($dist_name);
if ($self->{deps}->{cpan}->is_newer_version_available($dist_name, $repo_version)) {
$log->infof('New version available for dist \'%s\': %s', $dist_name, $dist->{version});
diff --git a/lib/App/ArchLinux/PackagerTools/Pacman.pm b/lib/App/ArchLinux/PackagerTools/Pacman.pm
index ec4f991..b9fe988 100644
--- a/lib/App/ArchLinux/PackagerTools/Pacman.pm
+++ b/lib/App/ArchLinux/PackagerTools/Pacman.pm
@@ -131,6 +131,30 @@ method get_package_version($pkgname) {
return $version;
}
+=head3 get_packages_versions
+
+ my $versions = $pacman->get_packages_versions($package_names);
+
+Return a hash that maps each package name to the version of that package in the
+pacman repository.
+
+=cut
+
+method get_packages_versions($package_names) {
+ my %versions;
+
+ open my $fh, '-|', qw(expac -S -1), '%n %v', '--', $package_names->@*;
+ while (<$fh>) {
+ my ($pkgname, $version) = split /\s/;
+ $versions{$pkgname} = $version;
+ $log->debugf("Package '%s' has version '%s' in repository", $pkgname, $version);
+ }
+ if ($package_names->@* != keys %versions) {
+ croak $log->error("Failed to find version for all packages. Got %d packages and %d versions were detected", scalar($package_names->@*), scalar(keys %versions));
+ }
+ return \%versions;
+}
+
=head3 get_perl_pkgname
my $pkgname = $pacman->get_perl_pkgname($dist_name);
@@ -162,12 +186,52 @@ pacman-specific information from the pacman's package version.
method get_perl_distribution_version($dist_name) {
my $pkgname = $self->get_perl_pkgname($dist_name);
my $version = $self->get_package_version($pkgname);
+ $version = $self->_clean_version($version);
+
+ $log->tracef("Found version '%s' for package '%s'", $version, $pkgname);
+ return $version;
+}
+
+=head3 get_perl_distribution_versions
+
+ my $distribution_names = ['App::ArchLinux::PackagerTools', 'DBI'];
+ my $versions = $pacman->get_perl_distribution_versions($distribution_names);
+ print $versions->{'DBI'}; # prints "1.642"
+
+Return a hash that maps a CPAN distribution name to the respective version of
+the CPAN distribution of the pacman repository package.
+
+=cut
+
+method get_perl_distribution_versions($distribution_names) {
+ my %pkgname_dist;
+ for my $dist_name ($distribution_names->@*) {
+ $pkgname_dist{$self->get_perl_pkgname($dist_name)} = $dist_name;
+ }
+
+ my $versions = $self->get_packages_versions([keys %pkgname_dist]);
+ my %dist_versions;
+ for my $key (keys $versions->%*) {
+ $dist_versions{$pkgname_dist{$key}} = $self->_clean_version($versions->{$key});
+ $log->debugf("Cleaned version of package '%s' is now '%s'", $key, $versions->{$key});
+ }
+ return \%dist_versions;
+
+}
+
+=head3 _clean_version
+
+ my $version = $self->_clean_version($version);
+
+Strip pacman-specific information (pkgrel, epoch) from a version string.
+
+=cut
+
+method _clean_version($version) {
# remove pkgrel
$version =~ s/-\d+(\.\d+)?$//;
# remove epoch
$version =~ s/^\d+://;
-
- $log->tracef("Found version '%s' for package '%s'", $version, $pkgname);
return $version;
}