Skip to content

Instantly share code, notes, and snippets.

@ap
Created June 12, 2012 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ap/2919035 to your computer and use it in GitHub Desktop.
Save ap/2919035 to your computer and use it in GitHub Desktop.
List CPAN distributions of an author that have Debian packages
#!/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;
@benkasminbullock
Copy link

use 5.012;

should be

use 5.014;

for the /r flag on line 17.

@ap
Copy link
Author

ap commented Jun 13, 2012

You are right. I fixed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment