Dancer icon indicating copy to clipboard operation
Dancer copied to clipboard

Plack - location of .psgi matters?

Open richardhuxton opened this issue 13 years ago • 3 comments

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

richardhuxton avatar May 09 '11 07:05 richardhuxton

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

alexkalderimis avatar Jun 10 '11 18:06 alexkalderimis

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 avatar Aug 01 '11 19:08 xsawyerx

On 1 August 2011 20:39, xsawyerx < [email protected]>wrote:

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

If it just dies with a meaningful error message, I think that will help a lot. Something like: "Unable to load config - checked: /path/dancer/tried based on .psgi path of /path/to/psgi"

When I first came across this, I'd done a lot of tidying on the project, but none of it terribly complex and I couldn't figure out why it wouldn't start any more.

That plus a way to explicitly tell Dancer where the app dir is would be fine. It's difficult to see how you can improve much on your current auto-guessing. I put the .psgi in $APPDIR/res but it could have easily been $APPDIR/res/development which makes it difficult to come up with heuristics that aren't just going to make things more confusing when they go wrong.

Richard Huxton

richardhuxton avatar Aug 02 '11 10:08 richardhuxton