Perl6: How to find all installed modules whose filename matches a pattern?

你说的曾经没有我的故事 提交于 2020-01-03 12:25:34

问题


Is it possible in Perl6 to find all installed modules whose file-name matches a pattern?

In Perl5 I would write it like this:

use File::Spec::Functions qw( catfile );

my %installed;
for my $dir ( @INC ) {
    my $glob_pattern = catfile $dir, 'App', 'DBBrowser', 'DB', '*.pm';
    map { $installed{$_}++ } glob $glob_pattern;
}

回答1:


There is currently no way to get the original file name of an installed module. However it is possible to get the module names

sub list-installed {
    my @curs       = $*REPO.repo-chain.grep(*.?prefix.?e);
    my @repo-dirs  = @curs>>.prefix;
    my @dist-dirs  = |@repo-dirs.map(*.child('dist')).grep(*.e);
    my @dist-files = |@dist-dirs.map(*.IO.dir.grep(*.IO.f).Slip);

    my $dists := gather for @dist-files -> $file {
        if try { Distribution.new( |%(from-json($file.IO.slurp)) ) } -> $dist {
            my $cur = @curs.first: {.prefix eq $file.parent.parent}
            take $_ for $dist.hash<provides>.keys;
        }
    }
}

.say for list-installed();

see: Zef::Client.list-installed()



来源:https://stackoverflow.com/questions/37350925/perl6-how-to-find-all-installed-modules-whose-filename-matches-a-pattern

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!