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

标签 module raku

在 Perl6 中是否可以找到文件名与模式匹配的所有已安装模块?

在 Perl5 中,我会这样写:

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;
}

最佳答案

目前无法获取已安装模块的原始文件名。但是可以获取模块名称

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();

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

关于module - Perl6 : How to find all installed modules whose filename matches a pattern?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37350925/

相关文章:

typescript - 为什么 ES2015 模块语法优于自定义 TypeScript 命名空间?

arrays - perl6 数组赋值 : pointer or copy?

raku - 如何显示值的类型层次结构?

raku - 为什么默认的 Raku if/while/loop/when block 都具有相同的标识值 (.WHICH)?

Perl6 : How could I make all warnings fatal?

encoding - 如何获得Perl 6可以理解的编码列表?

module - 如何在与程序相同的文件中声明和使用 Perl 6 模块?

ruby-on-rails - 模块自动将命名空间添加到正在调用的方法中

haskell - 如何在haskell中重新导出单个实体

python - python 中的积分函数 (x,y)