in reply to Post query to Metacpan API

Thank you both (haukex and stevieb) for showing different ways to do it. This is a good example of the benefits of using a module with a proper api. Without the module it needs a url, the decoder, and hash access, all of which could change; while the module neatly hides all the brittle parts behind a simple interface.
#!/usr/bin/perl # Get the latest version numbers of your favorite modules # (If they exist and have a normal version number...) # Usage: $0 Module::Name Other::Module Etc use strict; use warnings; use HTTP::Tiny; use JSON::PP 'decode_json'; use MetaCPAN::Client; my @ARGS = @ARGV ? @ARGV : ('MetaCPAN::Client','MCE','Plack'); my $http = HTTP::Tiny->new; for (@ARGS) { print "$_\t", decode_json($http->get( "http://fastapi.metacpan.org/v1/module/$_" )->{content})->{version},"\n" } my $cpan = MetaCPAN::Client->new; for (@ARGS){ printf "%s: %s\n", $_, $cpan->module($_)->version; }

Replies are listed 'Best First'.
Re^2: Post query to Metacpan API
by stevieb (Canon) on Sep 20, 2018 at 21:50 UTC

    I already answered this, but must have been too quick and possibly didn't hit the Submit button (very long day at work).

    You're very welcome.

    Explicit kudos to haukex who, as many Monks do, go unappreciated. I am glad that we were able to give you solutions that got you on your way.

    -stevieb