summaryrefslogtreecommitdiffstats
path: root/module-to-dist.pl
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2012-06-14 15:11:47 +0200
committerFlorian Pritz <bluewind@xinu.at>2012-06-14 15:11:47 +0200
commit8d4c36cccdedc9889b071bf5ec46980afb4a6dfd (patch)
tree3aea8dadcb160d5e048e1f01c85035ab7a30c9b2 /module-to-dist.pl
parentff100b14b1bc1621f1111f62df32b4f633bb011c (diff)
downloadbin-8d4c36cccdedc9889b071bf5ec46980afb4a6dfd.tar.gz
bin-8d4c36cccdedc9889b071bf5ec46980afb4a6dfd.tar.xz
add module-to-dist.pl
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'module-to-dist.pl')
-rw-r--r--module-to-dist.pl51
1 files changed, 51 insertions, 0 deletions
diff --git a/module-to-dist.pl b/module-to-dist.pl
new file mode 100644
index 0000000..8783bf8
--- /dev/null
+++ b/module-to-dist.pl
@@ -0,0 +1,51 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use v5.10;
+
+package Modules;
+
+use HTTP::Tiny qw();
+
+sub cpan_provider
+{
+ my ($module) = @_;
+ my $url = "http://cpanmetadb.plackperl.org/v1.0/package/$module";
+ my $http = HTTP::Tiny->new;
+ my $resp = $http->get($url);
+ return undef unless $resp->{'success'};
+
+ my ($cpanpath) = $resp->{'content'} =~ /^distfile: (.*)$/m
+ or return undef;
+
+ my $dist = $cpanpath;
+ $dist =~ s{\A.+/}{}; # remove author directory
+ $dist =~ s{-[^-]+\z}{}; # remove version and extension
+ $dist =~ s/-/::/;
+ return ($dist eq 'perl' ? undef : $dist);
+}
+
+package main;
+
+my %seen = ();
+my @modules;
+
+if (@ARGV == 0) {
+ # no args? read from stdin
+ @modules = <>;
+} else {
+ @modules = @ARGV;
+}
+
+for my $module (@modules) {
+ chomp($module);
+ next if ($module eq "");
+
+ my $dist = Modules::cpan_provider $module;
+
+ next unless $dist; # ignore undef
+ next if $seen{$dist}++; # ignore duplicates
+
+ say $dist;
+}
+