4

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 ?

9
  • What user are you running as, and what do the ownership/permissions look like in that directory?
    – Sobrique
    Commented Dec 17, 2014 at 14:01
  • @Sobrique : permissions are OK, the user is my account and the path is opened to anyone
    – LeGEC
    Commented Dec 17, 2014 at 14:04
  • Oh and this is probably wrong: #!/usr/bin/perl - you're using /usr/local.
    – Sobrique
    Commented Dec 17, 2014 at 14:04
  • 1
    I always use #!/usr/bin/env perl as the first line. Commented Dec 17, 2014 at 14:11
  • 1
    It's not your code doing it. Look at the EV.pm module, and on line 28 it has got: use EV 4.00. Which is ... loading itself, it seems?
    – Sobrique
    Commented Dec 17, 2014 at 14:16

2 Answers 2

1

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

5
  • I'm using 5.18. Indeed, using another event loop (for example AnyEvnt::Impl::Perl) works.
    – LeGEC
    Commented Dec 17, 2014 at 14:44
  • Yup. Perldelta. Edited.
    – Sobrique
    Commented Dec 17, 2014 at 14:46
  • Thx thx thx thx (<- the min chars turns polite people into extra-polite people)
    – LeGEC
    Commented Dec 17, 2014 at 14:47
  • AnyEvent::Impl::Perl doesn't have that 'use' line in there. That seems to be the culprit, but short of getting hacky with module code (which might work I guess...) the best answer might be upgrading Perl.
    – Sobrique
    Commented Dec 17, 2014 at 14:47
  • So given EV was changed on Dec 5th, it might be worth loading an older version. Manually download from CPAN and install. Or upgrade perl.
    – Sobrique
    Commented Dec 17, 2014 at 14:59
1

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
2
  • Well, technically you did find a bug, it's just one that's since been fixed. (And oddly, I've still got because of the version I've installed... Having said that, EV.pm isn't the same as AnyEvent::Impl::EV.pm
    – Sobrique
    Commented Dec 17, 2014 at 15:01
  • 1
    Please mark your solution as accepted so that others can see that your question has been solved.
    – Borodin
    Commented Dec 17, 2014 at 15:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.