A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Jump to

Quick reference

Guide to debugging Mojolicious applications

When MOJO_MODE=development or is not set, you should see exceptions rendered in the browser. But if you don't, try creating a templates/exception.html.ep template that contains this: %= $exception

You can also create error templates for different environments:
  • templates/exception.production.html.ep
  • templates/exception.development.html.ep

Mojo provides useful hooks that can be used to dump out debugging info:

# DEBUGGING HACK
$t->app->hook(before_dispatch => sub { # for request
my $c = shift;
return unless $ENV{APP_DEBUG};
print "*** Request body = ".$c->tx->req->body."\n";
print "*** Request headers = ".$c->tx->req->content->headers->to_string."\n";
print "*** End of headers\n";
});
$t->app->hook(after_dispatch => sub { # for response
my $c = shift;
return unless $ENV{APP_DEBUG};
print "*** Response body = ".$c->tx->res->body."\n";
print "*** Response headers = ".$c->tx->res->content->headers->to_string."\n";
print "*** End of headers\n";
});
#/ DEBUGGING HACK