Permalink
Browse files

Do not handle uploads older than 2 days and falling back to local mirror

  • Loading branch information...
1 parent dbec635 commit b3ea324c1f069c5e6fa232828d46cdcd54672dda @miyagawa committed Sep 2, 2009
Showing with 18 additions and 8 deletions.
  1. +18 −8 lib/App/CPAN/Fast.pm
View
@@ -8,11 +8,14 @@ use base qw(App::Cmd::Simple);
use Carp;
use CPAN::Inject;
+use Time::Piece;
use File::Temp;
use JSON;
use LWP::UserAgent;
use URI;
+my $duration = 2 * 24 * 60 * 60;
+
sub opt_spec {
return (
[ "install|i", "install the module" ],
@@ -55,19 +58,20 @@ sub usage {
sub install {
my($self, $dists) = @_;
- my @injected;
+ my @install;
for my $dist (@$dists) {
my $path = $self->inject($dist);
if ($path) {
- push @injected, $path;
+ push @install, $path;
} else {
- print "$dist not found.\n";
+ print "$dist is not found or not in the fresh uploads. Falling back to your mirror.\n";
+ push @install, $dist;
}
}
- if (@injected) {
+ if (@install) {
require CPAN;
- CPAN::Shell->install(@injected);
+ CPAN::Shell->install(@install);
}
}
@@ -77,7 +81,7 @@ sub inject {
my $res = $self->call("/search", { q => "$dist group:cpan" });
for my $entry (@{$res->{entries}}) {
- my $info = $self->parse_entry($entry->{body}) or next;
+ my $info = $self->parse_entry($entry->{body}, $entry->{date}) or next;
if ($info->{dist} eq $dist) {
return $self->do_inject($info);
}
@@ -103,13 +107,19 @@ sub do_inject {
sub display_results {
my($self, $res) = @_;
for my $entry (@{$res->{entries}}) {
- my $info = $self->parse_entry($entry->{body}) or next;
+ my $info = $self->parse_entry($entry->{body}, $entry->{date}) or next;
printf "%s-%s (%s)\n", $info->{dist}, $info->{version}, $info->{author};
}
}
sub parse_entry {
- my($self, $body) = @_;
+ my($self, $body, $date) = @_;
+
+ my $time = Time::Piece->strptime($date, "%Y-%m-%dT%H:%M:%SZ") or return;
+ if (time - $time->epoch > $duration) {
+ # entry found, but it's old
+ return;
+ }
if ($body =~ /^([\w\-]+) ([0-9\._]*) by (.+?) - <a.*href="(http:.*?\.tar\.gz)"/) {
return {

0 comments on commit b3ea324

Please sign in to comment.