#!/usr/bin/env perl use warnings 'FATAL' => 'all'; use strict; use LWP::UserAgent; use IO::Handle; # for autoflush my $dist = shift or die "Usage: $0 [CPAN dist name]\n"; my $url = "http://search.cpan.org/dist/$dist"; my $ua = LWP::UserAgent->new(); my $resp = $ua->get($url); die "$0: GET $url failed: ", $resp->status_line, "\n" unless $resp->is_success; $resp = $resp->content; my ($href) = $resp =~ m{\[Download\]} or die "$0: no download link found at $url\n"; my $file = $href; $file =~ s{\A.*/}{}; $href = "http://search.cpan.org" . $href; STDERR->autoflush(1); print STDERR "Downloading $file... "; $resp = $ua->get($href, ':content_file' => $file); die "$0: download of $file failed: ", $resp->status_line unless $resp->is_success; print STDERR "OK\n"; print "+ url $url\n"; print "+ source $href\n"; print "! perl-dist $file\n";