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