public
Created

List CPAN distributions of an author that have Debian packages

  • Download Gist
gistfile1.pl
Perl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#!/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;

use 5.012;

should be

use 5.014;

for the /r flag on line 17.

You are right. I fixed it.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.