The installed module was not found when starting the program

Context

Here is a perl script test 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.

However, I installed the package AnyEventusing cpanm, and the file is AnyEvent/Impl/EV.pmpresent in one of the paths @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

Question

How to fix it?

Additional remark

The error message says he is looking EV.pm, but I would expect AnyEvent/Impl/EV.pm.
How did it use AnyEvent::Impl::EV;turn out that which I wrote turned into at runtime perl is looking for EV.pm?

+4
source share
2 answers

, : 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
+1

cpan install AnyEvent , .

28 "EV.pm" use EV 4.00;. use EV; - - . "use" (, , , "" ?)

, - , @INC - ​​ , , .

- this module gets loaded automatically as required. , , use .

: perl. Perl 5.8.5 . 5.20.1 .

, perl , , , ? , 5.20.1. @INC.

Edit:

" @INC (, @INC) ​​ . , $_ glob ."

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

Source: https://habr.com/ru/post/1567994/


All Articles