Created
June 12, 2012 17:58
-
-
Save ap/2919035 to your computer and use it in GitHub Desktop.
List CPAN distributions of an author that have Debian packages
This file contains 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/env perl | |
use 5.014; | |
use strict; | |
use warnings; | |
use HTTP::Tiny (); | |
use JSON 'decode_json'; | |
sub get_dists_for_author { | |
my ( $author ) = @_; | |
my $url = sprintf 'http://api.metacpan.org/v0/release/_search?q=author:%s+AND+status:latest;fields=name;size=200', $author; | |
my $resp = HTTP::Tiny->new->get( $url ); | |
my $res = $resp->{'success'} ? decode_json $resp->{'content'} : undef; | |
die "Failed to query MetaCPAN\n" | |
unless $res | |
and ( not $res->{'timed_out'} ) | |
and $res->{'hits'}{'total'}; | |
map { $_->{'fields'}{'name'} =~ s/-[^-]+\z//r } @{ $res->{'hits'}{'hits'} } | |
} | |
sub has_debian_package { | |
my ( $dist ) = @_; | |
my $pkg = sprintf 'lib%s-perl', lc $dist; | |
my $resp = HTTP::Tiny->new->get( 'http://packages.debian.org/search?keywords=' . $pkg ); | |
$resp->{'success'} | |
? $resp->{'content'} =~ /<h3>Package \Q$pkg\E</ | |
: do { warn "Failed to query packages.debian.org for $pkg\n"; () } | |
} | |
my $author = $ARGV[0] // die "usage: $0 CPANID"; | |
print STDERR $author, ': '; | |
my @packaged = | |
grep { print STDERR $_, ', '; has_debian_package $_ } | |
sort { lc $a cmp lc $b } | |
do { get_dists_for_author $author }; | |
say STDERR "fin.\n"; | |
die "Nothing found.\n" if not @packaged; | |
say for @packaged; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
use 5.012;
should be
use 5.014;
for the /r flag on line 17.