diff options
Diffstat (limited to 'lib/App')
-rw-r--r-- | lib/App/ArchLinux/PackagerTools/CPAN.pm | 20 | ||||
-rw-r--r-- | lib/App/ArchLinux/PackagerTools/CPAN/PackagesDetailsFetcher.pm | 73 |
2 files changed, 78 insertions, 15 deletions
diff --git a/lib/App/ArchLinux/PackagerTools/CPAN.pm b/lib/App/ArchLinux/PackagerTools/CPAN.pm index e549408..b992a8f 100644 --- a/lib/App/ArchLinux/PackagerTools/CPAN.pm +++ b/lib/App/ArchLinux/PackagerTools/CPAN.pm @@ -5,11 +5,12 @@ use autodie; use CPAN::DistnameInfo; use Carp; use Function::Parameters; -use IPC::Run qw(run); use Log::Any qw($log); use Syntax::Keyword::Try; use version; +use App::ArchLinux::PackagerTools::CPAN::PackagesDetailsFetcher; + =head1 NAME App::ArchLinux::PackagerTools::CPAN - Methods to interact with CPAN @@ -37,6 +38,7 @@ Returns a new instance. =cut method new($class: $deps = {}) { + $deps->{packages_details_fetcher} //= App::ArchLinux::PackagerTools::CPAN::PackagesDetailsFetcher->new(); return $class->new_no_defaults($deps); } @@ -133,20 +135,7 @@ Set up the internal index of CPAN distributions method _build_dist_index() { $log->debug("Fetching CPAN modules index"); - my $out; - my $use_cpanplus_index = 1; - # TODO put this in a dedicated module for testing - if ($use_cpanplus_index) { - # This is mostly for development so we don't go over the network on each run. - my $packages_file = "$ENV{HOME}/.cpanplus/02packages.details.txt.gz"; - run ['zcat', $packages_file], \undef, \$out or die $log->error("Failed to fetch and uncompress CPAN module index: $?")."\n"; - } else { - # TODO cache the details file locally - # TODO when we have a cache of this, remove the $use_cpanplus_index part since that is worse than having our own cache - # TODO make the cpan mirror configurable - run [qw(curl -s ), "https://cpan.metacpan.org/modules/02packages.details.txt.gz"], '|', ['zcat'], \$out or die $log->error("Failed to fetch and uncompress CPAN module index: $?")."\n"; - } - + my $out = $self->{deps}->{packages_details_fetcher}->get_packages_data();; my %seen; my $line_number = 0; $log->debug("Building index..."); @@ -196,6 +185,7 @@ method _build_dist_index() { } } } + $log->debugf("CPAN modules index contains %s dists", scalar(keys $self->{dists}->%*)); } 1; diff --git a/lib/App/ArchLinux/PackagerTools/CPAN/PackagesDetailsFetcher.pm b/lib/App/ArchLinux/PackagerTools/CPAN/PackagesDetailsFetcher.pm new file mode 100644 index 0000000..7624836 --- /dev/null +++ b/lib/App/ArchLinux/PackagerTools/CPAN/PackagesDetailsFetcher.pm @@ -0,0 +1,73 @@ +package App::ArchLinux::PackagerTools::CPAN::PackagesDetailsFetcher; +use strictures; + +use autodie; +use Function::Parameters; +use Log::Any qw($log); +use IPC::Run qw(run); + +=head1 NAME + +App::ArchLinux::PackagerTools::CPAN::PackagesDetailsFetcher - Provide access to the 02packages.details CPAN file + +=head1 SYNOPSIS + + use App::ArchLinux::PackagerTools::CPAN::PackagesDetailsFetcher; + +=head1 DESCRIPTION + +Internal class that abstracts access to the 02packages file from CPAN. + +=head1 METHODS + +=head2 new + + my $fetcher = App::ArchLinux::PackagerTools::CPAN::PackagesDetailsFetcher->new(); + +Returns a new instance. + +=cut + +method new($class: $deps = {}) { + return $class->new_no_defaults($deps); +} + +method new_no_defaults($class: $deps = {}) { + my $self = {}; + bless $self, $class; + $self->{deps} = $deps; + return $self; +} + +=head2 Public Methods +=cut + +=head3 get_packages_data + + my $data = $fetcher->get_packages_data(); + +Return the uncompressed data of the 02packages.details.txt.gz file. + +=cut + +method get_packages_data() { + my $data; + my $use_cpanplus_index = 1; + # TODO put this in a dedicated module for testing + if ($use_cpanplus_index) { + # This is mostly for development so we don't go over the network on each run. + my $packages_file = "$ENV{HOME}/.cpanplus/02packages.details.txt.gz"; + run ['zcat', $packages_file], \undef, \$data or die $log->error("Failed to fetch and uncompress CPAN module index: $?")."\n"; + } else { + # TODO cache the details file locally + # TODO when we have a cache of this, remove the $use_cpanplus_index part since that is worse than having our own cache + # TODO make the cpan mirror configurable + run [qw(curl -s ), "https://cpan.metacpan.org/modules/02packages.details.txt.gz"], '|', ['zcat'], \$data or die $log->error("Failed to fetch and uncompress CPAN module index: $?")."\n"; + } + + return $data; +} + +1; + +__END__ |