Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

63 lines (48 sloc) 1.52 kB
name 'cpanfresh';
description 'Fetch the latest release from CPAN Fresh http://friendfeed.com/cpan';
author 'Tatsuhiko Miyagawa';
api_version 0.1;
my $entries;
hook search_module => 0, sub {
my $args = shift;
push @{$args->{uris}}, sub {
my $dist = $args->{module};
$dist =~ s/::/-/g;
$entries ||= eval { fetch_feed($args) } || [];
$args->{app}->diag("! Fetching CPAN Fresh failed: $@") if $@;
for my $info (@$entries) {
if ($info->{name} eq $dist) {
$args->{app}->chat("Found $dist on CPAN Fresh feed => $info->{url}\n");
return $info->{url};
}
}
return;
};
};
hook show_recent => sub {
my $args = shift;
$entries ||= fetch_feed($args);
return [ map $_->{dist}, @$entries ];
};
sub fetch_feed {
my $args = shift;
require JSON;
$args->{app}->chat("Querying http://friendfeed.com/cpan\n");
my $json = $args->{app}->get("http://friendfeed-api.com/v2/feed/cpan");
my $feed = eval { JSON::decode_json($json) } || {};
my @dists = map { parse_entry($_->{body}) || () } @{$feed->{entries}};
return \@dists;
}
sub parse_entry {
my $body = shift;
if ($body =~ m!^([\w\-]+) ([0-9\._]*) by (.+?) - <a.*href="(http:.*?/authors/id/(.*?\.tar\.gz))"!) {
return {
name => $1,
version => $2,
author => $3,
url => $4,
dist => $5,
};
}
return;
}
Jump to Line
Something went wrong with that request. Please try again.