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

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

问题描述

我想让另一个开发人员运行我写的Perl脚本。该脚本使用许多CPAN模块,必须先安装脚本才能运行。是否可以使脚本(或 perl binary)转储所有缺少的模块的列表?当我尝试运行脚本时,Perl打印出缺少的模块的名称,但这是冗长的,并没有一次列出所有缺少的模块。我想做一些例子:

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

甚至:

  $ list-deps说脚本>我的机器上的必需模块#
$ cpan -i`cat required-modules`#在他的机器上


$ b $有没有一个简单的方法呢?这不是一个显示屏,但我想让其他开发人员的生活更轻松。 (所需的模块被分散在几个文件中,所以手工制作列表并不容易,我不知道什么,我知道 PAR ,但是对于我想要的似乎有点太复杂了。)






更新:感谢Manni,这样做。我不知道%INC ,我只知道 @INC 。我用这样的方式解决了:

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

其中打印出来:

  Moose :: Meta :: TypeConstraint :: Registry 
Moose :: Meta :: Role :: Application :: ToClass
类:: C3
列表:: Util
Imager ::颜色
...

看起来这样会起作用。 p>

解决方案

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


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`

Or even:

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

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.)


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("\n", map { s|/|::|g; s|\.pm$||; $_ } keys %INC);

Which prints out:

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

Looks like this will work.

解决方案

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天全站免登陆