diff --git a/Changes b/Changes index 059b017a6..9f4444973 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,10 @@ {{$NEXT}} + [ BUG FIXES ] + * GH #447: Setting the apphandler now triggers the Dancer Runner + configuration change, which works. (Sawyer X) + + [ DOCUMENTATION ] * Fix doc for params(). Ported from Dancer#1025 (Stefan Hornburg) diff --git a/lib/Dancer2/Core/Role/ConfigReader.pm b/lib/Dancer2/Core/Role/ConfigReader.pm index cbffc589b..ce2b96c44 100644 --- a/lib/Dancer2/Core/Role/ConfigReader.pm +++ b/lib/Dancer2/Core/Role/ConfigReader.pm @@ -84,6 +84,11 @@ has global_triggers => ( require Carp; $Carp::Verbose = $traces ? 1 : 0; }, + + apphandler => sub { + my ( $self, $handler ) = @_; + Dancer2->runner->config->{'apphandler'} = $handler; + }, } }, ); diff --git a/t/lwp-protocol-psgi.t b/t/lwp-protocol-psgi.t new file mode 100644 index 000000000..2767ce525 --- /dev/null +++ b/t/lwp-protocol-psgi.t @@ -0,0 +1,34 @@ +#!/usr/bin/perl +use strict; +use warnings; +use Test::More tests => 5; +use LWP::UserAgent; + +eval "use LWP::Protocol::PSGI"; +plan skip_all => "LWP::Protocol::PSGI is needed for this test" if $@; + +my $psgi_app = do { + use Dancer2; + + set apphandler => 'PSGI'; + + get '/search' => sub { + my $q = param('q'); + is( $q, 'foo', 'Correct parameter to Google' ); + return 'bar'; + }; + + dance; +}; + +# Register the $psgi_app to handle all LWP requests +LWP::Protocol::PSGI->register($psgi_app); +my $ua = LWP::UserAgent->new; +isa_ok( $ua, 'LWP::UserAgent' ); + +my $res = $ua->get("http://www.google.com/search?q=foo"); +isa_ok( $res, 'HTTP::Response' ); + +ok( $res->is_success, 'Request is successful' ); +is( $res->content, 'bar', 'Correct response content' ); +