Skip to content

Instantly share code, notes, and snippets.

Created July 29, 2014 14:30
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/0061c88901e2e66a3dfe to your computer and use it in GitHub Desktop.
Save anonymous/0061c88901e2e66a3dfe to your computer and use it in GitHub Desktop.
Small snippet
sub lookup {
my $self = shift;
my $id = $self->stash->{url_id};
my $contact = $self->db->find_contact($id);
unless ($contact) {
$self->render_not_found;
return;
}
$self->stash(contact => $contact);
return 1;
}
sub view {
my $self = shift;
$self->render(template => 'view')
}
sub edit {
my $self = shift;
return $self->render(template => 'edit')
unless $self->req->method eq 'POST';
# Validation would be performed here as well...
my $contact = $self->stash->{contact};
$contact->name($self->param('name'));
# ...
$contact->update;
$self->redirect(...);
}
#
# I would like to be able to do something like this:
#
# $self->hook(around_dispatch => sub {
# my ($next, $c) = @_;
#
# $self->db->txn_do(sub {
# $next->();
# });
# });
#
# ... but only for a specific set of routes, not all requests.
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment