Skip to content


Dancer2 doesn't play well with LWP::Protocol::PSGI and/or apphandler => 'PSGI' doesn't kick in #447

gideondsouza opened this Issue · 7 comments

3 participants


The following example from the LWP::Protocol::PSGI POD, works with Dancer but not with Dancer2.

use LWP::UserAgent;
use LWP::Protocol::PSGI;

my $psgi_app = do {
    use Dancer;#ATTN : Change this to Dancer2 and the app hangs before this line
    setting apphandler => 'PSGI';
    get '/search' => sub {
        return 'googling ' . params->{q};
# Register the $psgi_app to handle all LWP requests
my $ua  = LWP::UserAgent->new;
my $res = $ua->get("");
print $res->content; # "googling bar"

So the above sample would hang when Dancer2 was used.

With some timely help from @mst-shadowcat turns out, if I add this : BEGIN { $ENV{DANCER_APPHANDLER} = 'PSGI';}, the second use statement, it works ok.

Not sure if it's just the following not kicking in

apphandler => 'PSGI' 

or something else.

PerlDancer member

This can be (didn't look into the code yet):

  • Setting being ignored, or more likely,
  • The usual problems with sets and triggers not working.

I don't understand what triggers are here? Could someone explain s'il vous plait.

PerlDancer member

@gideondsouza, atm just forget them. With the latest patch from @veryrusty you can use use Dancer apphandler=>"PSGI" and this issue can gets closed :dancers:


Alright :smile: I racked my brains a little generally about setting() and set() not working while doing command line options, couldn't figure it out too well. I thought this had something to do with it.

PerlDancer member

This is because set $key => $value changes applications, not the runner, where the the decision on which web server to run it under is done.

PerlDancer member

Fixed it locally. Setting up a test and pushing.

@xsawyerx xsawyerx added a commit that referenced this issue
@xsawyerx xsawyerx Make apphandler a global variable:
Recently when running

    set apphandler => 'PSGI'

it did not pick up because setting the apphandler affected only
the Dancer App, while the apphandler was (correctly) decided and
used by the Dancer Runner.

By making the "apphandler" option a global trigger that updates the
Dancer Runner object, this will now work.

Added a test that uses LWP::Protocol::PSGI, which exposed this
problem in GH #447.
PerlDancer member

Closed by 22523a3.

@xsawyerx xsawyerx closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.