I tried to fatpack my Perl script using fatpack utility from the App::Fatpacker module (on CentOS 6.6 64 bit running Perl 5.20). My script uses Log::Log4perl module for logging. fatpack utility complains about logging module:
fatpack trace collect_genomes_to_database.pl
collect_genomes_to_database.pl syntax OK
fatpack packlists-for `cat fatpacker.trace` >packlists
Can't locate object method "new" via package "Log::Log4perl::Appender" at ~/perl5/lib/perl5/Log/Log4perl/Logger.pm line 33.
Compilation failed in require at ~/perl5/lib/perl5/Log/Log4perl/Config.pm line 8.
BEGIN failed--compilation aborted at ~/perl5/lib/perl5/Log/Log4perl/Config.pm line 8.
Compilation failed in require at ~/perl5/lib/perl5/Log/Log4perl/Appender.pm line 9.
BEGIN failed--compilation aborted at ~/perl5/lib/perl5/Log/Log4perl/Appender.pm line 9.
Compilation failed in require at ~/perl5/lib/perl5/App/FatPacker.pm line 149.
BEGIN failed--compilation aborted at ~/perl5/bin/fatpack line 3.
Did someone succeed packing a script containing Log::Log4perl or is not doable?
Can you suggest some other method of making self-containing script?
You've found a bug in Log4perl.
One way around the problem is explicitly loading Log4perl before the rest.
PERL5OPT='-mLog::Log4perl' fatpack ...
This should step around the problem enough to make things work.
Hat Tip to mst and irc.perl.org#toolchain
The docs of App::FatPacker say that support is best provided through #toolchain on irc.perl.org. I took the liberty to share the question there.
Following is a log of the conversation with irrelevant stuff removed.
[16:02:15] <simbabque> mst: interesting question on fatpacker Is it possible to fatpack script using Log::Log4perl using App::Fatpacker?
[16:15:47] <mst> simbabque: not really, the user didn't use their brain and Mithaldu already solved the problem :)
[16:15:47] <Mithaldu> \o/
[16:16:08] <Mithaldu> main problem: user is using an old perl that doesn't tell them to load the module
[16:16:50] <mst> hm, actually, that appears to be the packlists-for command
[16:16:51] <mst> simbabque: wait
[16:16:53] <mst> fuck me running
[16:17:14] <mst> this may be an l4p bug
[16:17:31] <mst> simbabque: ooooh
[16:18:02] <mst> I think
[16:18:24] <mst> Log::Log4perl::Appender is loading ::Config which is loading ::Logger ... which is then trying to ->new on ::Appender before the method's been defined yet
[16:18:49] <mst> hence why packlists-for is blowing up trying to require modules
[16:19:29] <Mithaldu> that sounds various kinds of un fun
[16:21:00] <mst> or he's missed a chunk of error
[16:21:23] <simbabque> that he's missing something sounds likely
[16:21:28] <mst> ah, no, it is doing a require, I am right, and L4p is fucked
[16:21:32] <mst> 149 is 'require $t;'
[16:21:42] <mst> it's a circular require problem in l4p
[16:22:57] <Mithaldu> so he's gonna have to %INC munge?
[16:24:25] <mst> or somebody should hit MSCHILLI with a stick and get it fixed
[16:27:13] <mst> BINGO
[16:27:17] <mst> perl -e 'use Log::Log4perl::Appender;'
[16:27:19] <mst> BOOM
[16:30:15] <mst> https://github.com/mschilli/log4perl/issues/59
[16:30:16] <dipsy> [ Circular require causes explosion · Issue #59 · mschilli/log4perl · GitHub ]
[16:30:22] <mst> can somebody shove that onto SO please
[16:30:35] <Mithaldu> sure
[16:33:44] <kentnl> I imagined you could work around that by avoiding the problem module in packlists-for and copying it manually, after the "Tree" stage. But I haven't done a lot here.
[16:34:11] <mst> PERL5OPT='-mLog::Log4perl' fatpack ...
[16:34:13] -*- ether sees riche has already left :/
[16:34:14] <mst> would probably work
[16:34:26] <mst> yep
As Kent Fredric already posted, a workaround is to
$ PERL5OPT='-mLog::Log4perl' fatpack collect_genomes_to_database.pl
... but he was faster in posting it.
And that is the Perl Community at work. :)
Related
Having the exact issue as described at: perl module Class::HPLOO v0.23 install issue, I have attempted to correct the defined(#array) problem by editing to just (#array) and trying to rebuild the module. However I continue to get the return of:
$ make clean
$ perl Makefile.PL
$ make
$ make test: *** No rule to
make target `clean:'. Stop. Manifying 2 pod documents
PERL_DL_NONLAZY=1 "/opt/local/bin/perl5.26" "-Iblib/lib" "-Iblib/arch"
test.pl
1..42
# Running under perl version 5.026002 for darwin
# Current time local: Sun Aug 26 06:48:26 2018
# Current time GMT: Sat Aug 25 22:48:26 2018
# Using Test.pm version 1.26 not ok 1
# Failed test 1 in test.pl at line 9
# test.pl line 9 is: ok(!$#) ; Can't locate object method "new" via package "Foo" at test.pl line 11. make: *** [test_dynamic] Error 2
There are three issues with Class::HPLOO (which as I noted before, hasn't been updated since 2005) that make it fail with modern perls.
As discovered in the previous post,
the obsolete construct defined (#array) is used once in lib/Class/HPLOO.pm' and three times inlib/Class/HPLOO/Base.pm`. This construction has been prohibited since v5.22
The current directory (.) is no longer in #INC (as of v5.24, I think). So the lines in test.pl like
require "test/classtest.pm"
either all need to be rewritten as
require "./test/classtest.pm"
or an easier fix is to put
use lib '.';
at the top of the script.
There is a regular expression in lib/Class/HPLOO.pm, line 1077, with an "unescaped left brace"
$sub =~ s/(\S)( {) (\S)/$1$2\n$FIRST_SUB_IDENT $3/gs ;
{ is a regex metacharacter, and since v5.22 it has been illegal to use it in a context where it is not indicating a quantity. The fix, as the error message suggests, is to escape it.
$sub =~ s/(\S)( \{) (\S)/$1$2\n$FIRST_SUB_IDENT $3/gs ;
Make these three changes to the code you download from CPAN and the module should build on modern Perls. If you're feeling helpful, you can submit a bug report (linking to this post, if you want) or even a patch with an email to bug-Class-HPLOO#rt.cpan.org
come across this issue today, so I fixed it following the answer above. if anyone want to save some time.
I create a repo with the changes. https://github.com/swuecho/Class_HPLOO.git
I am getting the error below during make test on Solaris even though the make command executed successfully.
Can't load '/e/scripts/Proc-ProcessTable-0.53/blib/arch/auto/Proc/ProcessTable/ProcessTable.so' for module Proc::ProcessTable: ld.so.1: perl: fatal: /e/scripts/Proc-ProcessTable-0.53/blib/arch/auto/Proc/ProcessTable/ProcessTable.so: wrong ELF class: ELFCLASS32 at /usr/perl5/5.10/lib/5.10.0/sun4-solaris-thread-multi-64/DynaLoader.pm line 203.
Can someone help and suggest what is wrong here?
Facing below issue when execute catalyst server script.
Couldn't load class (Catalyst::Script::Server) because: "ensure_class_loaded" is not exported by the Catalyst::Utils module
Can't continue after import errors at /opt/madhan/lib/perl5/Catalyst/ScriptRole.pm line 7.
BEGIN failed--compilation aborted at /opt/madhan/lib/perl5/Catalyst/ScriptRole.pm line 7.
Compilation failed in require at /usr/lib/perl5/site_perl/5.8.8/Module/Runtime.pm line 313.
Compilation failed in require at /opt/madhan/lib/perl5/Catalyst/ScriptRunner.pm line 13.
Catalyst::ScriptRunner::find_script_class("Catalyst::ScriptRunner", "testsite", "Server") called at /opt/madhan/lib/perl5/Catalyst/ScriptRunner.pm line 42
Catalyst::ScriptRunner::run("Catalyst::ScriptRunner", "testsite", "Server") called at /opt/madhan/testsite/script/testsite_server.pl line 8
Will the perl 5.8.8 support Catalyst MVC?
This is a bug in Catalyst. There was some type-checking code in Catalyst::ScriptRole (since 2012!) which was completely broken, but the brokenness was only visible in particular circumstances — namely, if a script provided a loader_class to Catalyst::ScriptRole that wasn't already a loaded class (likely no one ever has), or if the system has a very old version of UNIVERSAL.pm such as that shipped with perl 5.8. It's this second case that you're running into.
I've pushed a patch to Catalyst-Runtime to resolve this problem; hopefully it will be released soon it's included in Catalyst-Runtime 5.90115.
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 ?
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).
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
I'm having a strange error trying to run a Perl script with ActivePerl on Windows XP:
>perl -d quick_translate_missing.pl < translate_en.txt > new.txt
Loading DB routines from perl5db.pl version 1.33
Editor support available.
Enter h or `h h' for help, or `perldoc perldebug' for more help.
main::(quick_translate_missing.pl:9):
9: my $not_translated = '\'EN_([\w\s]+)\'';
El sistema no puede hallar la ruta especificada.
Unknown error
Compilation failed in require at C:/Perl/lib/Term/ReadLine/Perl.pm line 65.
at C:/Perl/lib/Term/ReadLine/Perl.pm line 65
Term::ReadLine::Perl::new('Term::ReadLine', 'perldb', 'GLOB(0x1968f34)',
'GLOB(0x1927e7c)') called at C:/Perl/lib/perl5db.pl line 6068
DB::setterm called at C:/Perl/lib/perl5db.pl line 2241
DB::DB called at quick_translate_missing.pl line 9
Attempt to reload Term/ReadLine/readline.pm aborted.
Compilation failed in require at C:/Perl/lib/Term/ReadLine/Perl.pm line 65.
END failed--call queue aborted at quick_translate_missing.pl line 65.
at quick_translate_missing.pl line 65
"El sistema no puede hallar la ruta especificada." means "System cannot find the specified path". The line the error is referring to is from Perl.pm:
eval {require Term::ReadLine::readline}; die $# if $#;
What I understand is that it cannot find Term::ReadLine::readline, but the file C:\Perl\lib\Term\ReadLine\readline.pm is there. Also PATH is set correctly since I can run perl interpreter from anywhere without specifing the path.
The error happens only when using standard output redirection (>). Script passed to debugger doesn't matter, it crashes on all if output redirection used.
Any clues? Thanks in advance!
This may not help you if you must have a specific perl version, but I found this same error with my perl 5.8.5 install. I could not upgrade on one machine (for legacy code reasons), but I ran it in another perl environment with the latest perl (v5.14.2) and this "debugger" bug has been solved (although I suspect you may have the same result by updating the Term::ReadLine::* modules as well). By the way, this isn't specific to ActivePerl -- I saw this on Linux as well.