-
-
Save mjgardner/1c9f9816a7e6c67687e8701b35891d5b to your computer and use it in GitHub Desktop.
Demo Dancer2 app for PSGI debugging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Local::MyApp; | |
use Dancer2; | |
use Feature::Compat::Try; | |
our $VERSION = '0.1'; | |
get '/say-hello' => sub { | |
try { | |
no strict 'refs'; | |
my $method = 'build_frob'; | |
$method->(); | |
} | |
catch ($e) { | |
status 'error'; | |
send_as JSON => {error => $e}; | |
} | |
send_as JSON => {message => 'Hello world!'}; | |
}; | |
sub build_frob { | |
return; | |
} | |
true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Test::Most; | |
use Test::WWW::Mechanize::PSGI; | |
use JSON::MaybeXS; | |
use Local::MyApp; # name of your app's main module goes here | |
my $mech = Test::WWW::Mechanize::PSGI->new( | |
# a Dancer2 app, so to_app returns a PSGI coderef | |
app => Local::MyApp->to_app(), | |
); | |
$mech->get_ok('/say-hello'); | |
lives_and { | |
my $json = decode_json($mech->content); | |
cmp_deeply( $json, {message => 'Hello world!'} ); | |
} 'message is Hello world!'; | |
done_testing; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment