运行程序时找不到已安装的模块

时间:2014-12-17 13:57:35

标签: perl anyevent perl5.18

上下文

这是一个perl测试脚本,我想看看如何使用AnyEvent的特定事件循环:

# file test.pl :
#!/usr/bin/perl

use strict;
use warnings;

use AnyEvent;
use AnyEvent::Impl::EV;

my $cv = AnyEvent->condvar;

my $wait_one_and_a_half_seconds = AnyEvent->timer (
  after => 0.5,  # after how many seconds to invoke the cb?
  cb    => sub { # the callback to invoke
     print ("Hello from callback\n");
     $cv->send;
  },
);

# now wait till our time has come
$cv->recv;

问题

以下是运行上述代码时出现的错误:

$ perl test.pl
Can't locate EV.pm in @INC (you may need to install the EV module) (@INC
contains: /etc/perl /usr/local/lib/perl/5.18.2 /usr/local/share/perl/5.18.2
/usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.18 /usr/share/perl/5.18
/usr/local/lib/site_perl .) at /usr/local/lib/perl/5.18.2/AnyEvent/Impl/EV.pm
line 28.
BEGIN failed--compilation aborted at /usr/local/lib/perl/5.18.2/AnyEvent/Impl/EV.pm line 28.
Compilation failed in require at test.pl line 6.
BEGIN failed--compilation aborted at test.pl line 6.

然而,我使用AnyEvent安装了cpanm包,而AnyEvent/Impl/EV.pm路径中存在@INC文件:

$ ls /usr/local/lib/perl/5.18.2/AnyEvent/Impl/
Cocoa.pm     Event.pm  FLTK.pm  IOAsync.pm  Perl.pm  Qt.pm  UV.pm
EventLib.pm  EV.pm     Glib.pm  Irssi.pm    POE.pm   Tk.pm

问题

我该如何解决这个问题?

额外评论

错误消息显示它正在寻找EV.pm,但我原本期望AnyEvent/Impl/EV.pm 为什么我写的use AnyEvent::Impl::EV;在运行时变为perl is looking for EV.pm

2 个答案:

答案 0 :(得分:1)

尝试使用cpan install AnyEvent重现此问题,并确认我收到同样的错误。

'EV.pm'的第28行是use EV 4.00;。你的use EV;有点像红鲱鱼 - 这不是错误的根源。这个模块明确地包含一个“使用”行(坦率地说有点奇怪,它似乎'使用'本身?)

除非@INC路径发生变化,否则我认为不会有效 - 我只能假设此模块的加载是在其他地方处理的,而不解构源代码。

引用手册页 - this module gets loaded automatically as required。所以你可能首先不需要use它。

编辑:刚刚比较了perl版本。 Perl 5.8.5显示相同的行为。我的5.20.1安装没有。

我不确定升级perl是否是正确的步骤,但它可能值得尝试?我会试着找出为什么5.20.1有效。这与处理@INC有关。

编辑:

“处理@INC过滤器的返回值(由@INC中的子程序返回的子程序)已经以各种方式修复。先前绑定的变量处理不当,将$ _设置为引用或类型地球可能会导致崩溃。”

http://perldoc.perl.org/perl5200delta.html

我认为这可能是问题所在。

你肯定并不孤单: http://www.cpantesters.org/cpan/report/d5939816-a510-11e0-bd04-22322d9f2468

自: http://cpansearch.perl.org/src/MLEHMANN/AnyEvent-7.08/Changes

5.29 Sun Dec 5 10:49:21 CET 2010 - convert EV backend to EV 4.00 API (so better upgrade EV too).

答案 1 :(得分:1)

错误消息实际上是指向应该执行的操作的非常正确和前向的指针:有一个EV包需要单独安装:

$ sudo cpanm EV
--> Working on EV
Fetching http://www.cpan.org/authors/id/M/ML/MLEHMANN/EV-4.18.tar.gz ... OK
Configuring EV-4.18 ... OK
Building and testing EV-4.18 ... OK
Successfully installed EV-4.18
1 distribution installed

之后,一切正常:

$ cat test.pl 
#!/usr/bin/perl

use strict;
use warnings;

use AnyEvent;
use EV;

my $wait_one_and_a_half_seconds = AnyEvent->timer (
  after => 0.5,  # after how many seconds to invoke the cb?
  cb    => sub { # the callback to invoke
     print ("Hello from callback\n");
  },
);

# now wait till our time has come
EV::run();

$ perl test.pl 
Hello from callback