Run an app:
MOJO_USERAGENT_DEBUG=1 perl -I lib ~/path/to/morbo --verbose --watch lib --watch local bin/app.pl
View existing routes:
perl -I lib bin/app.pl routes
Find the code that defines the routes:
grep -r '$r->get' .
grep -r '$r->post' .
perl -I lib bin/app.pl dbic_migration --action=install
Write a script that uses the app config, etc:
See Mojolicious::Command
Debug Test::Mojo:
print $t->tx->res->body; # See also guide to debugging
Catch unexpected exceptions:
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
use Mojo::Base 'Mojolicious'; | |
use Try::Tiny; | |
$self->hook( | |
around_action => sub { | |
my ( $next, $c, $action, $last ) = @_; | |
my $request = $c->req; | |
return try { | |
return $next->(); | |
} | |
catch { | |
my $error = $_; | |
if ( $error->$_isa('App::KnownException') ) { | |
$self->handle($error); # I meant to do that | |
} | |
else { | |
my $message = defined $error ? "$error" : "Unknown error"; | |
$self->log->error($error); | |
return $c->reply->exception($message); | |
} | |
} | |
} | |
); |
my @routes = sort map { $_->to_string } map { @{ $_->children } }
grep { $_->name eq 'distro' || $_->name eq 'candidates' }
@{ $t->app->routes->children };