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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.