如何找到我的 Perl 脚本的模块依赖项? [英] How do I find the module dependencies of my Perl script?

查看:34
本文介绍了如何找到我的 Perl 脚本的模块依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望另一个开发人员运行我编写的 Perl 脚本.该脚本使用了许多必须在脚本运行之前安装的 CPAN 模块.是否可以让脚本(或 perl 二进制文件)转储所有丢失模块的列表?当我尝试运行脚本时,Perl 会打印出丢失模块的名称,但这是冗长的,并且不会一次列出所有丢失的模块.我想做类似的事情:

I want another developer to run a Perl script I have written. The script uses many CPAN modules that have to be installed before the script can be run. Is it possible to make the script (or the perl binary) to dump a list of all the missing modules? Perl prints out the missing modules’ names when I attempt to run the script, but this is verbose and does not list all the missing modules at once. I’d like to do something like:

$ cpan -i `said-script --list-deps`

甚至:

$ list-deps said-script > required-modules # on my machine
$ cpan -i `cat required-modules` # on his machine

有没有简单的方法来做到这一点?这不是表演障碍,但我想让其他开发人员的生活更轻松.(所需的模块散布在多个文件中,因此我很难在不遗漏任何内容的情况下手动制作列表.我知道 PAR,但对于我想要的来说似乎有点太复杂了.)

Is there a simple way to do it? This is not a show stopper, but I would like to make the other developer’s life easier. (The required modules are sprinkled across several files, so that it’s not easy for me to make the list by hand without missing anything. I know about PAR, but it seems a bit too complicated for what I want.)

更新:谢谢,曼尼,这样就好了.我不知道%INC,我只知道@INC.我解决了这样的问题:

Update: Thanks, Manni, that will do. I did not know about %INC, I only knew about @INC. I settled with something like this:

print join("
", map { s|/|::|g; s|.pm$||; $_ } keys %INC);

打印出来的:

Moose::Meta::TypeConstraint::Registry
Moose::Meta::Role::Application::ToClass
Class::C3
List::Util
Imager::Color
…

看起来这会起作用.

推荐答案

您可以在脚本末尾转储 %INC.它将包含所有使用和必需的模块.但是当然,这只有在您不有条件地要求模块时才有用(如果 $bar 则要求 Foo).

You could dump %INC at the end of your script. It will contain all used and required modules. But of course, this will only be helpful if you don't require modules conditionally (require Foo if $bar).

这篇关于如何找到我的 Perl 脚本的模块依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆