Skip to content

Instantly share code, notes, and snippets.

@mjgardner
Created July 6, 2021 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjgardner/1c9f9816a7e6c67687e8701b35891d5b to your computer and use it in GitHub Desktop.
Save mjgardner/1c9f9816a7e6c67687e8701b35891d5b to your computer and use it in GitHub Desktop.
Demo Dancer2 app for PSGI debugging
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;
#!/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