-
-
Save anonymous/0061c88901e2e66a3dfe to your computer and use it in GitHub Desktop.
Small snippet
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
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