LoginSignup
4

More than 5 years have passed since last update.

特定のCPAN Authorの人気モジュールを調べる

Last updated at Posted at 2012-03-16

「この人たくさんモジュール出してるけどどれがよく使われてるんだろなー」を調べる。テストがpassした数で降順ソートしている。バージョンアップしたばかりのモジュールは少なめに出てしまうから、よく使われている度を正確に出せてはいないのだけど。

出力はこんな感じになる。(sartak氏の出したモジュールを例に)

pass    version name    abstract
1509    0.03    MooseX-HasDefaults  default "is" to "ro" or "rw" for all attributes
1153    0.45    Template-Declare    Perlish declarative templates
1114    1.08    Class-Method-Modifiers  provides Moose-like method modifiers
1095    0.18    Any-Moose   use Moose or Mouse modules
1031    0.15    Test-Spelling   check for spelling errors in POD files
...
#!/usr/bin/env perl
use common::sense;
use LWP::Simple;
use JSON::XS;
use Data::Dumper;
use LWP::UserAgent;

my $ID = 'sartak';  # or whoever!

my $path = 'http://api.metacpan.org/v0/release/_search';
my $search = {
    query => {
        filtered => {
            query  => { match_all => {} },
            filter => {
                and => [
                    { term => { author => uc($ID) } },
                    { term => { status => 'latest' } }
                ]
            },
        }
    },
    sort => [
        'distribution', { 'version_numified' => { reverse => \1 } }
    ],
    fields => [qw(distribution abstract date tests version_numified)],
    size   => 1000,
};
my $ua = LWP::UserAgent->new;
my $res = $ua->post($path, Content => encode_json($search));
my $data = decode_json($res->content);
$data = [
    sort {$b->{pass} <=> $a->{pass}}
    map {
        +{
            name     => $_->{fields}->{distribution},
            pass     => $_->{fields}->{tests}->{pass} || 0,
            version  => $_->{fields}->{version_numified},
            abstract => $_->{fields}->{abstract} || '',
       }
    }
    @{$data->{hits}->{hits}}
];
say join "\t", qw(pass version name abstract);
say join "\t", @$_{qw(pass version name abstract)} for @$data;

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4