Skip to content

Instantly share code, notes, and snippets.

@ltriant
Created June 20, 2017 03:28
Show Gist options
  • Select an option

  • Save ltriant/f4d7fa6f0650bc024476994d9d4ff82c to your computer and use it in GitHub Desktop.

Select an option

Save ltriant/f4d7fa6f0650bc024476994d9d4ff82c to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use warnings;
use strict;
use Mojo::UserAgent;
die "usage: cpanver <module>\n" unless @ARGV;
my ($module) = @ARGV;
my $url = sprintf 'http://fastapi.metacpan.org/v1/package/%s', $module;
my $ua = Mojo::UserAgent->new;
my $path = $module;
$path =~ s{::}{/}g;
$path =~ s{$}{.pm};
eval { require $path };
my $ver = $@ ? "not installed" : $module->VERSION;
print "Installed: $ver\n";
my $tx = $ua->get($url);
if ($tx->res->is_success) {
my $json = $tx->res->json;
print "Latest: ", $json->{version}, "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment