diff options
Diffstat (limited to 'bin/macros/perl-cpan')
-rwxr-xr-x | bin/macros/perl-cpan | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/bin/macros/perl-cpan b/bin/macros/perl-cpan new file mode 100755 index 0000000..810ad8d --- /dev/null +++ b/bin/macros/perl-cpan @@ -0,0 +1,42 @@ +#!/Users/juster/perl5/perlbrew/perls/perl-5.14.1/bin/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{\[<a href="([^"]+)">Download</a>\]} + or die "$0: no download link found at $url\n"; + +unless (-d 'src') { + mkdir 'src' or die "$0: mkdir src: $!" +} + +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' => "src/$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"; +system "perl-dist src/$file"; +if ($? != 0) { + printf STDERR "$0: failed to run perl-dist%s\n", ($! ? " ($!)" : q{}); + exit 1; +} |