Plack - location of .psgi matters? #518

Open
richardhuxton opened this Issue May 9, 2011 · 3 comments

4 participants

@richardhuxton

Using plackup (or starman - presumably others too) with a .psgi file in a dir other than "$app/bin" fails. Steps to reproduce below:

$ cat /tmp/app.psgi
use Dancer;
use Plack;
load_app 'test1';

use Dancer::Config 'setting';
setting apphandler => 'PSGI';
Dancer::Config->load;

my $app1 = sub {
    my $env = shift;
    my $request = Dancer::Request->new( $env );
    Dancer->dance( $request );
};

Minimal file as above.

$ dancer -a test1
$ cp /tmp/app.psgi test1/bin/
$ mkdir test1/res
$ cp /tmp/app.psgi test1/res/

$ plackup test1/bin/app.psgi 
Subroutine Plack::Sandbox::test1_2fbin_2fapp_2epsgi::setting redefined at /usr/share/perl/5.10/Exporter.pm line 66.
 at test1/bin/app.psgi line 5
[29747]  core @0.000017> loading application test1 in /srv/Projects/oldford_db/perllib/lib/perl5/Dancer.pm l. 209
[29747]  core @0.000709> initializing appdir to: `/srv/Projects/oldford_db/src/tmp/test1' in /srv/Projects/oldford_db/perllib/lib/perl5/Dancer.pm l. 264
HTTP::Server::PSGI: Accepting connections at http://0:5000/
^C

$ plackup test1/res/app.psgi 
Subroutine Plack::Sandbox::test1_2fres_2fapp_2epsgi::setting redefined at /usr/share/perl/5.10/Exporter.pm line 66.
 at test1/res/app.psgi line 5
Error while loading test1/res/app.psgi: unable to load application test1 : Can't locate test1.pm in @INC (@INC contains: ...) at /srv/Projects/oldford_db/perllib/lib/perl5/Dancer/ModuleLoader.pm line 31.
 at test1/res/app.psgi line 3

If I then add the path to .../test1/lib to PERL5LIB it starts up, but something is still not right.

plackup test1/res/app.psgi 
Subroutine Plack::Sandbox::test1_2fres_2fapp_2epsgi::setting redefined at /usr/share/perl/5.10/Exporter.pm line 66.
 at test1/res/app.psgi line 5
HTTP::Server::PSGI: Accepting connections at http://0:5000/

Note the lack of "core..." debugging lines about "loading application" or "initializing appdir".

Add the following line to the bottom of test1.pm

debug "app = " . config->{appname};

Running with bin/app.psgi give the debug line you would expect, but res/app.psgi gives a "uninitialized value" warning showing the config hasn't been loaded.

Platform: linux, perl 5.10.0, latest dancer and plack

@alexkalderimis

I noticed this too after an upgrade, and had to move the script out of a script directory into bin

@franckcuny franckcuny was assigned Jul 5, 2011
@xsawyerx
PerlDancer member

I think the problems stems from us trying to understand your application structure, and it does that by looking for a 'bin' directory. This is probably not the best practice.

I'll look into it tomorrow.

@xsawyerx xsawyerx was assigned Aug 1, 2011
@richardhuxton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment