如何获取已安装的 CPAN 模块的列表?
除了
perldoc <module name>
单独尝试我喜欢的任何 CPAN 模块或浏览文件系统并查看目录之外,我不知道我们安装了哪些模块。
获取已安装的每个 CPAN 模块的大列表的最简单方法是什么? 从命令行或其他方式。
Aside from trying
perldoc <module name>
individually for any CPAN module that takes my fancy or going through the file system and looking at the directories, I have no idea what modules we have installed.
What's the easiest way to just get a big list of every CPAN module installed? From the command line or otherwise.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(28)
这个问题在 Perl FAQ 中得到了解答,可以通过安装
perldoc -q
来快速找到答案。 简而言之,归结为使用ExtUtils::Installed
或使用File::Find
,这两种方法的变体已在本线程之前介绍过。您还可以找到常见问题解答条目 “如何查找我的系统上安装了哪些模块?”。 您可以通过查看 perlfaq 来查看所有常见问题解答的列表
This is answered in the Perl FAQ, the answer which can be quickly found with
perldoc -q installed
. In short, it comes down to usingExtUtils::Installed
or usingFile::Find
, variants of both of which have been covered previously in this thread.You can also find the FAQ entry "How do I find which modules are installed on my system?" in perlfaq3. You can see a list of all FAQ answers by looking in perlfaq
编辑:CPAN 常见问题解答中提供了有关它的(一点)更多信息
Edit: There's a (little) more info about it in the CPAN FAQ
perldoc -q displayed
声称
cpan -l
可以解决问题,但它对我不起作用。 另一个选项:cpan -a
确实会输出已安装软件包的良好列表,并且具有将它们写入文件的良好副作用。
perldoc -q installed
claims that
cpan -l
will do the trick, however it's not working for me. The other option:cpan -a
does spit out a nice list of installed packages and has the nice side effect of writing them to a file.
值得注意的是,perldoc perllocal 只会报告通过 CPAN 安装的模块。 如果有人手动安装模块,它将找不到它们。 另外,如果有多人安装模块并且 perllocal.pod 处于源代码控制之下,人们可能会错误地解决冲突并损坏列表(例如,在工作中就发生过这种情况)。
遗憾的是,解决方案似乎是使用 File::Find 或类似的东西遍历@INC。 但是,这不仅可以查找模块,还可以查找发行版中的相关模块。 例如,除了 Test::Harness 的实际发行版名称之外,它还会报告 TAP::Harness 和 TAP::Parser(假设您有版本 3 或更高版本)。 您可以将它们与发行版名称匹配并丢弃那些不匹配的名称,但随后您可能会丢弃本地构建和安装的模块。
我相信 brian d foy 的 backpan 索引工作应该有代码将其交给 .pm 文件,并且它将尝试推断分布,但即使这样有时也会失败,因为包中的内容不一定已安装(请参阅 Devel::Cover ::Inc 为例)。
It's worth noting that perldoc perllocal will only report on modules installed via CPAN. If someone installs modules manually, it won't find them. Also, if you have multiple people installing modules and the perllocal.pod is under source control, people might resolve conflicts incorrectly and corrupt the list (this has happened here at work, for example).
Regrettably, the solution appears to be walking through @INC with File::Find or something similar. However, that doesn't just find the modules, it also finds related modules in a distribution. For example, it would report TAP::Harness and TAP::Parser in addition to the actual distribution name of Test::Harness (assuming you have version 3 or above). You could potentially match them up with distribution names and discard those names which don't match, but then you might be discarding locally built and installed modules.
I believe brian d foy's backpan indexing work is supposed to have code to hand it at .pm file and it will attempt to infer the distribution, but even this fails at times because what's in a package is not necessarily installed (see Devel::Cover::Inc for an example).
您可以尝试 ExtUtils-Installed,但这只在
.packlists,因此它可能会丢失人们手动将内容移入
@INC
的模块。我为一位朋友编写了 App-Module-Lister非 shell Web 托管帐户上的 CGI 脚本。 您只需获取模块文件并将其作为文件名上传,您的服务器会将其视为 CGI 脚本。 它没有标准库之外的依赖项。 按原样使用它或窃取代码。
它输出模块及其版本的列表:
我一直想将其作为一项功能添加到
cpan
工具中,所以我也会这样做。 [时间流逝] 现在,我在cpan
中有一个-l
开关。 在发布之前我还有其他一些事情要做,但是它在 github 中< /a>. 如果您不想等待,您可以尝试使用-a
开关来创建自动捆绑包,尽管这会在列表中放置一些 Pod。祝你好运;
You can try ExtUtils-Installed, but that only looks in
.packlist
s, so it may miss modules that people moved things into@INC
by hand.I wrote App-Module-Lister for a friend who wanted to do this as a CGI script on a non-shell web hosting account. You simple take the module file and upload it as a filename that your server will treat as a CGI script. It has no dependencies outside of the Standard Library. Use it as is or steal the code.
It outputs a list of the modules and their versions:
I've been meaning to add this as a feature to the
cpan
tool, so I'll do that too. [Time passes] And, now I have a-l
switch incpan
. I have a few other things to do with it before I make a release, but it's in github. If you don't want to wait for that, you could just try the-a
switch to create an autobundle, although that puts some Pod around the list.Good luck;
这是一个可以解决问题的脚本:
Here a script which would do the trick:
尝试使用以下命令
l
,您将列出所有已安装的模块。来自 手册页:
Try the following command
With
l
you will List all installed modules.From man page:
您可以通过在终端中使用instmodsh命令来获取系统中安装的perl模块的列表。它会询问您三个选项以增强输出:
You can get list of perl modules installed in you system by using
instmodsh
command in your terminal.It will ask you three option in order to enhance the output they are:在 Linux/Unix 上,我使用这个简单的命令:
它扫描 @INC 中的所有文件夹并查找任何 *.pm 文件。
On Linux/Unix I use this simple command:
It scans all folder in
@INC
and looks for any *.pm file.我喜欢为此使用 CPAN 'r' 命令。 您可以使用旧样式进入 CPAN shell:
或者,在大多数较新的系统上,有一个“cpan”命令,因此此命令将带您进入 shell:(
您通常必须使用“sudo”来运行它root,或在运行之前使用“su -”成为root,除非您已设置cpan以让您以普通用户身份运行它,但如果您在此计算机上没有root,则可以安装。仍然使用 CPAN shell 来查找此信息,但您将无法安装模块,并且第一次运行时可能需要进行一些设置。)
然后,一旦您进入 cpan shell 中,您可以使用“r”命令报告所有已安装的模块及其版本。 所以,在“cpan>”处 提示时,输入“r”。 这将列出所有已安装的模块及其版本。 使用 '?' 以获得更多帮助。
I like to use the CPAN 'r' command for this. You can get into the CPAN shell with the old style:
or, on most newer systems, there is a 'cpan' command, so this command will get you to the shell:
(You typically have to use 'sudo' to run it as root, or use 'su -' to become root before you run it, unless you have cpan set up to let you run it as a normal user, but install as root. If you don't have root on this machine, you can still use the CPAN shell to find out this information, but you won't be able to install modules, and you may have to go through a bit of setup the first time you run it.)
Then, once you're in the cpan shell, you can use the 'r' command to report all installed modules and their versions. So, at the "cpan>" prompt, type 'r'. This will list all installed modules and their versions. Use '?' to get some more help.
这是在 *nix 中执行此操作的一种非常 hacky 的方法,您会得到一些您并不真正关心的内容(即:警告::注册等),但它应该为您提供可通过以下方式访问的每个 .pm 文件的列表珀尔。
Here's a really hacky way to do it in *nix, you'll get some stuff you don't really care about (ie: warnings::register etc), but it should give you a list of every .pm file that's accessible via perl.
所有无法安装 perldoc 或其他模块,并想知道哪些模块可用(CPAN 或其他)的人,以下内容适用于 linux 和 Mingw32/64:
是的,这很混乱。 是的,它报告的内容可能比您想要的更多。 但是如果你将它通过管道传输到一个文件中,你可以轻松地检查,比如说,存在哪些 dbm 接口:
这就是为什么我最终出现在这个页面上(失望)
(我意识到这并不能完全回答OP的问题,但我我将其发布给所有因与我相同的原因而来到这里的人,这就是堆栈***的问题,即使它存在,也几乎不可能找到您所问的问题,但堆栈***几乎总是存在。谷歌最热门!)
All those who can't install perldoc, or other modules, and want to know what modules are available (CPAN or otherwise), the following works for linux and Mingw32/64:
Yes, it's messy. Yes, it probably reports more than you want. But if you pipe it into a file, you can easily check for, say, which dbm interfaces are present:
Which is why I ended up on this page (disappointed)
(I realise this doesn't answer the OP's question exactly, but I'm posting it for anybody who ended up here for the same reason I did. That's the problem with stack*** it's almost imposisble to find the question you're asking, even when it exists, yet stack*** is nearly always google's top hit!)
这是@JamesThomasMoon1979 重写为一句台词的脚本
Here's a script by @JamesThomasMoon1979 rewritten as a one-liner
答案可以在 Perl 常见问题解答列表。
您应该浏览 Perl 附带的优秀文档
The answer can be found in the Perl FAQ list.
You should skim the excellent documentation that comes with Perl
尝试
man perllocal
或perldoc perllocal
。Try
man perllocal
orperldoc perllocal
.我昨天写了一个 perl 脚本来完成这个任务。 该脚本使用“::”作为分隔符返回 @INC 中安装的 perl 模块的列表。 使用 -
或
调用脚本 目前,脚本会跳过当前目录('.'),因为我在递归软链接方面遇到问题,但您可以通过将第 17 行中的 grep 函数从 更改为
just 来包含它,
该脚本可以可以在此处找到。
I wrote a perl script just yesterday to do exactly this. The script returns the list of perl modules installed in @INC using the '::' as the separator. Call the script using -
OR
As of now the script skips the current directory('.') since I was having problems with recursing soft-links but you can include it by changing the grep function in line 17 from
to just,
The script can be found here.
这是另一个命令行工具,用于列出所有已安装的 .pm 文件:
查找与常规匹配的已安装 Perl 模块表达式
Here is yet another command-line tool to list all installed .pm files:
Find installed Perl modules matching a regular expression
要在不使用像 ls(1) 这样的外部程序的情况下遍历 @INC 目录树,可以使用
File::Find::Rule
模块,该模块具有很好的声明式界面。另外,您希望过滤掉重复项,以防以前的 Perl 版本包含相同的模块。 执行此操作的代码如下所示:
在运行结束时,您还将所有模块名称作为 %seen 哈希中的键。 该代码可以修改为将规范文件名(在 $file 中给出)保存为键的值,而不是查看的次数。
To walk through the @INC directory trees without using an external program like ls(1), one could use the
File::Find::Rule
module, which has a nice declarative interface.Also, you want to filter out duplicates in case previous Perl versions contain the same modules. The code to do this looks like:
At the end of the run, you also have all your module names as keys in the %seen hash. The code could be adapted to save the canonical filename (given in $file) as the value of the key instead of a count of times seen.
以下内容对我有用。
The following worked for me.
Perl 食谱包含脚本“pmdesc”的多次迭代,可以完成您想要的操作。
Google 搜索“Perl Cookbook pmdesc”,您会发现 其他问答网站上的文章、网上的一些代码清单、解决方案的讨论,甚至一些改进。
the Perl cookbook contains several iterations of a script "pmdesc" that does what you want.
Google-search for "Perl Cookbook pmdesc" and you'll find articles on other Q&A Sites, several code listings on the net, a discussion of the solution, and even some refinements.
这是一个 Perl 单行代码,它将打印出已安装模块的列表:
只需确保您已安装 Data::Dumper。
Here's a Perl one-liner that will print out a list of installed modules:
Just make sure you have Data::Dumper installed.
Windows 用户只需执行 Windows 资源管理器搜索即可找到它。
Windows users just do a Windows Explorer search to find it.
尝试“perldoc -l”:
$ perldoc -l Log::Dispatch
/usr/local/share/perl/5.26.1/Log/Dispatch.pm
Try "perldoc -l":
$ perldoc -l Log::Dispatch
/usr/local/share/perl/5.26.1/Log/Dispatch.pm
这可能是一种替代且简单的方法:
this could be an alternative and easy way:
当您输入 Perl 脚本时,所有已安装的模块都以 .pm 文件形式保存在 @INC 中的文件夹下,因此一个小的 bash 脚本将为您完成这项工作:
As you enter your Perl script you have all the installed modules as .pm files below the folders in @INC so a small bash script will do the job for you:
对于 Linux,最简单的获取方法是:
For Linux the easiest way to get is,