在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;
}
答案 0 :(得分:5)
目前无法获取已安装模块的原始文件名。但是,可以获取模块名称
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();