From 8d4c36cccdedc9889b071bf5ec46980afb4a6dfd Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Thu, 14 Jun 2012 15:11:47 +0200 Subject: add module-to-dist.pl Signed-off-by: Florian Pritz --- module-to-dist.pl | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 module-to-dist.pl (limited to 'module-to-dist.pl') 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; +} + -- cgit v1.2.3-24-g4f1b