8
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

マシンにインストールされているCPANモジュール一覧を出す

仕事で使うなら各モジュールのバージョンまでちゃんと管理しなきゃだけど(OrePANとか使う必要がある)、趣味でやるようなゆるい開発用に。

#!/usr/bin/env perl

use strict;
use warnings;
use Perl6::Say;
use Path::Class;
use Pod::Parser;
use List::MoreUtils qw/uniq/;
use Regexp::Assemble;

my @perllocals = do {
    my $version = do {
        my $info = `perl -v`;
        ($info =~ /\(v(5[\.\d]+)\)/)[0];
    };

    my $search;
    for my $path (@INC) {
        if ($path =~ /(.+?$version)/) {
            $search = $1 and last;
        }
    }
    map {chomp $_; $_} `find $search -name 'perllocal.pod'`;
};

my $search = do {
    my $ra = Regexp::Assemble->new;
    $ra->add('^Module');
    $ra->add('[^:]:[^:]');
    $ra->re
};

my $parser = Pod::Parser->new;

my @modules = (
    uniq
    sort
    grep {
        $_ && $_ !~ /$search/;
    }
    map {
        $_->{'-ptree'}->[0] =~ /^(.+)\|/;
    }
    grep {
        ref($_) eq 'Pod::InteriorSequence'
    }
    map {
        @{$parser->parse_text(scalar file($_)->slurp)};
    }
    @perllocals
);

say $_ for @modules;
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
8
Help us understand the problem. What are the problem?