Installed module not found when running program

3.5k views Asked by At

Context

Here is a perl test script, in which I wanted to see how you can use a specific event loop with 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;

Problem

Here is the error I get when running the above code :

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

Yet I installed the AnyEvent package using cpanm, and the AnyEvent/Impl/EV.pm file is present in one of the @INC path :

$ 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

Question

How do I fix this ?

Extra remark

The error message says it is looking for EV.pm, but I would have expected AnyEvent/Impl/EV.pm.
How come the use AnyEvent::Impl::EV; I wrote got turned into perl is looking for EV.pm at runtime ?

2

There are 2 answers

2
LeGEC On BEST ANSWER

The error message was actually a very correct and forward pointer to what should be done : there is an EV package which needs to be installed separately :

$ 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

After that, everything works :

$ 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
5
Sobrique On

Just tried to reproduce this with cpan install AnyEvent and can confirm I get the same error.

Line 28 of 'EV.pm' is use EV 4.00;. Your use EV; is a bit of a red herring - that's not the source of the error. This module explicitly includes a 'use' line (which frankly is a bit wierd, it's 'using' itself it seems?)

I don't think that's ever going to work, unless the @INC path is changed - I can only assume that the loading of this module is handled elsewhere, without deconstructing source code.

Referencing the man page - this module gets loaded automatically as required. So you probably don't need to use it in the first place.

Edit: Just compared perl versions. Perl 5.8.5 shows the same behaviour. My 5.20.1 install doesn't.

I'm not sure upgrading perl is necessarily the right step, but it might be worth trying? I'll try and figure out why 5.20.1 works though. It's got to be something to do with handling of @INC.

Edit:

"The handling of return values of @INC filters (subroutines returned by subroutines in @INC) has been fixed in various ways. Previously tied variables were mishandled, and setting $_ to a reference or typeglob could result in crashes."

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

I think that might be what the problem is.

You're certainly not alone in having this: http://www.cpantesters.org/cpan/report/d5939816-a510-11e0-bd04-22322d9f2468

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