That's cool but too complicated
The original question was "How does one query the metacpan api from perl?", to which the IMO best answer is indeed MetaCPAN::Client. Why reject it so quickly? I'd recommend having a look at the documentation. You'll see it's actually pretty easy to use.
Here's what fetching the version of a distro looks like without the module:
use warnings; use strict; use HTTP::Tiny; use URI; use Cpanel::JSON::XS qw/decode_json/; my $http = HTTP::Tiny->new; my @modules = @ARGV ? @ARGV : ('MetaCPAN::Client'); for my $mod (@modules) { my $uri = URI->new('http://fastapi.metacpan.org/v1/module'); $uri->path_segments( $uri->path_segments, $mod ); my $resp = $http->get($uri); die "$uri: $resp->{status} $resp->{reason}\n" unless $resp->{s +uccess}; my $api = decode_json($resp->{content}); print "$mod: $api->{version}\n"; }
Update: In comparison, stevieb showed just how easy using the module makes it.
In reply to Re^3: Post query to Metacpan API
by haukex
in thread Post query to Metacpan API
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |