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:
my $T = File::Spec->catdir(File::Basename::dirname(__FILE__), 'templat
+es');
Because PAR::Packer-based executables run out of a temp directory, the relative path returned by __FILE__ is not found.
Changing
line
21 to
my $T = File::Spec->catdir(File::Basename::dirname($INC{'Mojolicious/L
+ite.pm'} || __FILE__), 'templates');
results in the binary version of webapp.pl running successfully.
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