Last active
October 21, 2016 20:25
-
-
Save yanick/7389d107ed48a04290c5af159f314598 to your computer and use it in GitHub Desktop.
quick metacpan cli interface
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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