8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Posted at

仕事で使うなら各モジュールのバージョンまでちゃんと管理しなきゃだけど(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;
8
8
0

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
8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?