summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/App/ArchLinux/PackagerTools/CPAN.pm99
1 files changed, 56 insertions, 43 deletions
diff --git a/lib/App/ArchLinux/PackagerTools/CPAN.pm b/lib/App/ArchLinux/PackagerTools/CPAN.pm
index c48469a..024c21e 100644
--- a/lib/App/ArchLinux/PackagerTools/CPAN.pm
+++ b/lib/App/ArchLinux/PackagerTools/CPAN.pm
@@ -9,6 +9,8 @@ use Log::Any qw($log);
use Syntax::Keyword::Try;
use version;
+use App::ArchLinux::PackagerTools::Cache;
+use App::ArchLinux::PackagerTools::Config;
use App::ArchLinux::PackagerTools::CPAN::PackagesDetailsFetcher;
=head1 NAME
@@ -39,6 +41,8 @@ Returns a new instance.
method new($class: $context, $deps = {}) {
$deps->{packages_details_fetcher} //= App::ArchLinux::PackagerTools::CPAN::PackagesDetailsFetcher->new($context);
+ $deps->{cache} //= App::ArchLinux::PackagerTools::Cache->new($context);
+ $deps->{config} //= App::ArchLinux::PackagerTools::Config->new($context);
return $class->new_no_defaults($context, $deps);
}
@@ -140,57 +144,66 @@ Set up the internal index of CPAN distributions
method _build_dist_index() {
return if (scalar(keys $self->{dists}->%*) > 0);
- $log->debug("Fetching CPAN modules index");
- my $out = $self->{deps}->{packages_details_fetcher}->get_packages_data();;
- my %seen;
- my $line_number = 0;
- $log->debug("Building index...");
- for (split /\n/, $out) {
- # skip meta info (first 9 lines)
- next if $line_number++ < 9;
+ my $cache = $self->{deps}->{cache};
+ my $conf = $self->{deps}->{config}->get_config();
+ my $indexes = $cache->compute("cpan-index", $conf->{cpan}->{cache_timeout}, sub {
+ $log->debug("Building index...");
- #$log->tracef("Parsing line: %s", $_);
- my ($module_name, $module_version, $file) = split /\s+/;
+ my $out = $self->{deps}->{packages_details_fetcher}->get_packages_data();;
+ my %seen;
+ my $line_number = 0;
+ my $indexes;
+ for (split /\n/, $out) {
+ # skip meta info (first 9 lines)
+ next if $line_number++ < 9;
- next if $seen{$file}++ > 0;
+ #$log->tracef("Parsing line: %s", $_);
+ my ($module_name, $module_version, $file) = split /\s+/;
- my $dist = CPAN::DistnameInfo->new($file);
- if (!defined $dist->{dist}) {
- $log->debugf("Failed to parse file: %s", $file);
- next;
- }
+ next if $seen{$file}++ > 0;
- my $dist_name = $dist->{dist};
- my $dist_name_lc = lc($dist_name);
+ my $dist = CPAN::DistnameInfo->new($file);
+ if (!defined $dist->{dist}) {
+ $log->debugf("Failed to parse file: %s", $file);
+ next;
+ }
- my $dist_version;
- try {
- $dist_version = version->parse($dist->{version});
- } catch {
- $log->debugf("Skipping dist with invalid version: %s", $@);
- $log->debugf("Skipped dist is: %s", $dist);
- next;
- }
+ my $dist_name = $dist->{dist};
+ my $dist_name_lc = lc($dist_name);
- my $index_dist;
- my $index_version = version->parse($self->{dists}->{$dist_name}->{version});
- my $index_name = $self->{dist_lc_map}->{$dist_name_lc};
- $index_dist = $self->{dists}->{$index_name} if defined $index_name;
-
- if (!defined($index_dist)
- || (defined($index_dist) && $index_name eq $dist_name && $dist_version > $index_version)
- ) {
- $self->{dist_lc_map}->{$dist_name_lc} = $dist_name;
- $self->{dists}->{$dist_name} = {
- dist_name => $dist_name,
- version => $dist->{version},
- };
- } else {
- if ($dist_name ne $index_name && $dist_version < $index_version) {
- confess $log->errorf("Key '%s' already exists in lc_map. This requires a manual exception to map correctly.\nExisting: %s\nCurrent: %s", $dist_name_lc, $index_dist, {$dist->%{qw(dist version)}});
+ my $dist_version;
+ try {
+ $dist_version = version->parse($dist->{version});
+ } catch {
+ $log->debugf("Skipping dist with invalid version: %s", $@);
+ $log->debugf("Skipped dist is: %s", $dist);
+ next;
+ }
+
+ my $index_dist;
+ my $index_version = version->parse($indexes->{dists}->{$dist_name}->{version});
+ my $index_name = $indexes->{dist_lc_map}->{$dist_name_lc};
+ $index_dist = $indexes->{dists}->{$index_name} if defined $index_name;
+
+ if (!defined($index_dist)
+ || (defined($index_dist) && $index_name eq $dist_name && $dist_version > $index_version)
+ ) {
+ $indexes->{dist_lc_map}->{$dist_name_lc} = $dist_name;
+ $indexes->{dists}->{$dist_name} = {
+ dist_name => $dist_name,
+ version => $dist->{version},
+ };
+ } else {
+ if ($dist_name ne $index_name && $dist_version < $index_version) {
+ confess $log->errorf("Key '%s' already exists in lc_map. This requires a manual exception to map correctly.\nExisting: %s\nCurrent: %s", $dist_name_lc, $index_dist, {$dist->%{qw(dist version)}});
+ }
}
}
- }
+ return $indexes;
+ });
+ $self->{dist_lc_map} = $indexes->{dist_lc_map};
+ $self->{dists} = $indexes->{dists};
+
$log->debugf("CPAN modules index contains %s dists", scalar(keys $self->{dists}->%*));
}