Sometimes, it’s humongous revolutions. Most of the time, it’s itsy bitsy evolutionary steps. Today’s hack definitively sits in the second category, but I have the feeling that it’s a little dab of abstraction that is going to provide a lot of itch relief.
You see, MetaCPAN does not only have a pretty face, but also has a smashing backend that can be used straight-up for fun and profit.
Accessing REST endpoints is not hard, but it’s a little bit of a low-level chore. In Perl space, there is already MetaCPAN::API to abstract.
[perl] my $ua = LWP::UserAgent;my $me = decode_json(
$ua->get( ‘https://api.metacpan.org/author/YANICK’
)->content;
[/perl>
<p>into</p>
[perl] my $mcpan = MetaCPAN::API;my $me = $mcpan->author(‘YANICK’);
[/perl]
In JavaScript-land? Well, there was jQuery, of course:
[javascript]$.get(‘https://api.metacpan.org/author/YANICK’).success( function(data) {alert( ‘hi there ‘ + data.name );
});
[/javascript]
But now there is also metacpan.js:
[javascript]$.metacpan().author(‘YANICK’).success( function(data) {alert( ‘hi there ‘ + data.name );
});
[/javascript]
The plugin is still very simple and only implements author()
, module()
, release()
, and file()
. And each of these methods is nothing but a glorified wrapper around the underlying $.ajax()
calls. But then again, isn’t the road to heaven paved with glorified wrappers? (Which could be more of an indication of the terrible littering habits of angels than anything else, mind you.)
Enjoy (and/or fork, depending on how much the current code is already scratching your own itch)!
No comments