| 1 | package Menlo::Index::Mirror; | ||
| 2 | use strict; | ||
| 3 | use parent qw(CPAN::Common::Index::Mirror); | ||
| 4 | use Class::Tiny qw(fetcher); | ||
| 5 | |||
| 6 | use File::Basename (); | ||
| 7 | use File::Spec (); | ||
| 8 | use URI (); | ||
| 9 | |||
| 10 | our $HAS_IO_UNCOMPRESS_GUNZIP = eval { require IO::Uncompress::Gunzip }; | ||
| 11 | |||
| 12 | my %INDICES = ( | ||
| 13 | # mailrc => 'authors/01mailrc.txt.gz', | ||
| 14 | packages => 'modules/02packages.details.txt.gz', | ||
| 15 | ); | ||
| 16 | |||
| 17 | sub refresh_index { | ||
| 18 | my $self = shift; | ||
| 19 | for my $file ( values %INDICES ) { | ||
| 20 | my $remote = URI->new_abs( $file, $self->mirror ); | ||
| 21 | $remote =~ s/\.gz$// | ||
| 22 | unless $HAS_IO_UNCOMPRESS_GUNZIP; | ||
| 23 | my $local = File::Spec->catfile( $self->cache, File::Basename::basename($file) ); | ||
| 24 | $self->fetcher->($remote, $local) | ||
| 25 | or Carp::croak( "Cannot fetch $remote to $local"); | ||
| 26 | if ($HAS_IO_UNCOMPRESS_GUNZIP) { | ||
| 27 | ( my $uncompressed = $local ) =~ s/\.gz$//; | ||
| 28 | IO::Uncompress::Gunzip::gunzip( $local, $uncompressed ) | ||
| 29 | or Carp::croak "gunzip failed: $IO::Uncompress::Gunzip::GunzipError\n"; | ||
| 30 | } | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | 1; |