sub myaction : Chained('.') PathPart('myaction') POST { my ( $self, $c ) = @_; my $form = MyApp::Form->new; $form->process(params => $c->req->body_params); my $error_sub = sub { $c->response->status(400); $c->stash( results => { form => $form->render, }, ); $c->detach(); }; if ( $form->is_valid ) { try { $form->update_model; } catch($e) { $form->add_form_error($e); $error_sub->(); }; } else { $error_sub->(); } } #### my sub error { $c->response->status(400); $c->stash( results => { form => $form->render, }, ); $c->detach(); }