Skip to content

Instantly share code, notes, and snippets.

@nekoya
Created December 13, 2009 04:07
Show Gist options
  • Select an option

  • Save nekoya/255269 to your computer and use it in GitHub Desktop.

Select an option

Save nekoya/255269 to your computer and use it in GitHub Desktop.
get latest local::lib archive
#!/usr/bin/perl
use strict;
use warnings;
use WWW::Mechanize;
my $wget = 'wget';
my $authors_url = 'http://search.cpan.org/~apeiron/';
my $mech = WWW::Mechanize->new;
my $res = $mech->get($authors_url);
check_response($res, "failed get auhor's page");
$res = $mech->follow_link(url_regex => qr/^local-lib-1.\d+/);
check_response($res, "failed get local-lib page");
my $link = $mech->find_link(text => 'Download');
my $url = $link->url;
die "got unexpected url:$url"
unless $url =~ ?^/CPAN/authors/id/A/AP/APEIRON/local-lib-1\.\d+\.tar\.gz$?;
system "$wget " . $link->url_abs;
sub check_response {
my ($res, $msg) = @_;
if ( !$res->is_success || $res->code != 200 ) {
die $msg;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment