metaperl has asked for the wisdom of the Perl Monks concerning the following question:
NEW SIMPLE EXAMPLE
I'm updating this node with a very simple test case that demonstrates the problem and does not require Mojolicious:# works in plain perl # fails with this compilation line: # pp -P -r -v 99 -o packed.pl somefile.pl BEGIN { use File::Spec; for (@INC) { if ( !ref $_ && -d $_ && !File::Spec->file_name_is_absolute($_ +) ) { $_ = File::Spec->rel2abs($_); } } } sub hello { my $file = __FILE__; warn "My file name is $file. Here is my contents:"; open(my $fh, "<", $file); my @data = <$fh>; warn "@data"; } hello(); 1;
OLD NODE
With the latest Mojolicious from CPAN, if you use PAR::Packer to create an executable for webapp.pl by running pack.pl (by cloning this repo) then Mojolicious::Controller will fail to find the template directory because it uses this code to do so:Because PAR::Packer-based executables run out of a temp directory, the relative path returned by __FILE__ is not found. Changing line 21 tomy $T = File::Spec->catdir(File::Basename::dirname(__FILE__), 'templat +es');
results in the binary version of webapp.pl running successfully.my $T = File::Spec->catdir(File::Basename::dirname($INC{'Mojolicious/L +ite.pm'} || __FILE__), 'templates');
good questions, no answer yet
The author of Mojolicious asked a good question regarding my described symptoms:18:18 <@sri> even if it's in a temporary directory why would __FILE__ return the wrong file?
related nodes
this person did not run into this problem for some reason
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: __FILE__ fails in Mojolicious app built with PAR::Packer
by Anonymous Monk on Sep 10, 2011 at 04:38 UTC | |
by metaperl (Curate) on Sep 10, 2011 at 20:27 UTC | |
by metaperl (Curate) on Sep 10, 2011 at 20:40 UTC | |
Re: __FILE__ fails in app built with PAR::Packer
by Anonymous Monk on Sep 10, 2011 at 22:38 UTC |
Back to
Seekers of Perl Wisdom