-
-
Save hirose31/333089 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use URI::Escape qw( uri_escape ); | |
use HTTP::Lite; | |
use URI; | |
use Web::Scraper; | |
my $query = $ARGV[0] or die "query required\n"; | |
my $url = 'http://search.cpan.org/search?mode=module&n=100&q=' . uri_escape( $query ); | |
my $scraper = scraper { | |
process 'body div.item', 'result[]' => scraper { | |
process 'h2.sr' , 'module' => 'TEXT'; | |
process 'small a', 'distro' => 'TEXT'; | |
}; | |
}; | |
my $http = HTTP::Lite->new; | |
$http->request($url); | |
my $content = $http->body; | |
$content =~ s/<!--item-->/<div class="item">/g; | |
$content =~ s/<!--end item-->/<\/div>/g; | |
my $result = $scraper->scrape($content)->{result}; | |
my %by_distro; | |
for (@$result) { | |
push @{ $by_distro{ $_->{distro} } }, $_->{module}; | |
} | |
for my $distro (sort keys %by_distro) { | |
my($disname, $disver) = ($distro =~ /(^.+)(?:\.pm)?-([^-]+)$/); | |
$disname =~ s/-/::/g; | |
printf "%s (%s)\n", $disname, $disver; | |
my @modnames = @{$by_distro{$distro}}; | |
next if (@modnames == 1 && $modnames[0] eq $disname); | |
printf " %s\n", $_ for @modnames; | |
} | |
__END__ | |
example: | |
$ ./search_cpan.pl sha1 | |
CGI::Application::Plugin::Authentication (0.17) | |
CGI::Application::Plugin::Authentication::Driver::Filter::sha1 | |
CGI::Session (3.95) | |
CGI::Session::ID::SHA1 | |
Cache::Memcached::Indexable (0.03) | |
Cache::Memcached::Indexable::Logic::DigestSHA1 | |
Digest::HMAC (1.02) | |
Digest::HMAC_SHA1 | |
Digest::SHA1 (2.12) | |
Egg::Plugin::SessionKit (3.05) | |
Egg::Model::Session::ID::SHA1 | |
Egg::Release::Authorize (0.06) | |
Egg::Model::Auth::Crypt::SHA1 | |
HTTP::Session (0.34) | |
HTTP::Session::ID::SHA1 | |
Javascript::SHA1 (1.04) | |
Mail::DKIM (0.37) | |
Mail::DKIM::Algorithm::dk_rsa_sha1 | |
Mail::DKIM::Algorithm::rsa_sha1 | |
Mail::SpamAssassin (2.64) | |
Mail::SpamAssassin::SHA1 | |
Net::OAuth (0.22) | |
Net::OAuth::SignatureMethod::HMAC_SHA1 | |
Net::OAuth::SignatureMethod::RSA_SHA1 | |
OAuth::Lite (1.26) | |
OAuth::Lite::SignatureMethod::HMAC_SHA1 | |
OAuth::Lite::SignatureMethod::RSA_SHA1 | |
OpenID::Lite (0.01_02) | |
OpenID::Lite::SessionHandler::DH::SHA1 | |
OpenID::Lite::SignatureMethod::HMAC_SHA1 | |
RDFStore (0.42) | |
RDFStore::Stanford::Digest::SHA1 | |
Schema::RDBMS::AUS (0.04) | |
Schema::RDBMS::AUS::Crypt::SHA1 | |
Template::Plugin::Digest::SHA1 (0.03) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment