Skip to content

Instantly share code, notes, and snippets.

@yanick
Last active October 21, 2016 20:25
Show Gist options
  • Save yanick/7389d107ed48a04290c5af159f314598 to your computer and use it in GitHub Desktop.
Save yanick/7389d107ed48a04290c5af159f314598 to your computer and use it in GitHub Desktop.
quick metacpan cli interface
#!/usr/bin/env perl
=usage
mcpan moosex
=cut
use 5.20.0;
use warnings;
use Web::Query;
use Text::ASCIITable;
my $url = 'https://metacpan.org/search?search_type=modules&size=200&q='.shift;
my $doc = wq($url);
my $table = Text::ASCIITable->new({ utf8 => 0 });
$table->setCols(qw/ module description distribution author /);
$doc->find('big strong')->each(sub{
my $author = $_->parent->parent->find('.author')->text;
my $distro = ( split '/', $_->parent->parent->find('.author')->next->attr('href') )[-1];
my @row = split '-', $_->text, 2;
push @row, '' unless @row == 2;
push @row, $distro, $author;
$table->addRow( @row );
});
print $table;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment