Skip to content

Instantly share code, notes, and snippets.

Created July 29, 2014 15:27
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 anonymous/071ec9c6ef72704d35f2 to your computer and use it in GitHub Desktop.
Save anonymous/071ec9c6ef72704d35f2 to your computer and use it in GitHub Desktop.
Wrapping a Mojolicious chain with custom code
$wrapped = $r->under('/')->to(cb => sub {
my $c = shift;
# Skip, without this we end up in an infinite loop.
$c->match->current($c->match->current + 1);
warn "mark 1";
$c->continue;
warn "mark 4";
# Or, for example:
# $c->app->db->txn_do(sub { $c->continue; });
# We're already done, make sure we don't continue.
return;
});
my $foo = $wrapped->under('/foo')->to(cb => sub {
warn "mark 2";
return 1;
});
$foo->get('/bar')->to(cb => sub {
warn "mark 3";
shift->render(text => 'done');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment