Perl6:如何查找文件名与模式匹配的所有已安装模块? [英] Perl6: How to find all installed modules whose filename matches a pattern?
本文介绍了Perl6:如何查找文件名与模式匹配的所有已安装模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Perl6中是否可以找到所有已安装的文件名与模式匹配的模块?
Is it possible in Perl6 to find all installed modules whose file-name matches a pattern?
在Perl5中,我会这样写:
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;
}
推荐答案
当前无法获取已安装模块的原始文件名.但是,可以获取模块名称
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();
请参阅: Zef :: Client.list-installed()
这篇关于Perl6:如何查找文件名与模式匹配的所有已安装模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文