Skip to content

Instantly share code, notes, and snippets.

@preaction
Created February 4, 2020 20:54
Show Gist options
  • Save preaction/8a9e2cf56e13ff40d3df9fe9e4999bb6 to your computer and use it in GitHub Desktop.
Save preaction/8a9e2cf56e13ff40d3df9fe9e4999bb6 to your computer and use it in GitHub Desktop.
Extend Yancy controller to add a modified by field
package MyApp::Controller::ModifiedBy;
use Mojo::Base 'Yancy::Controller::Yancy';
sub _add_modified_by {
my ( $c ) = @_;
$c->req->param( modified_by => $c->current_uid );
if ( my $item = $c->req->json ) {
$item->{ modified_by } = $c->current_uid;
}
}
sub create {
my ( $c ) = @_;
_add_modified_by( $c );
return $c->SUPER::create;
}
sub set {
my ( $c ) = @_;
_add_modified_by( $c );
return $c->SUPER::set;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment