[dancer-users] Dancer::Plugin::SimpleCRUD and 'add_edit_row_pre_save' hook question

David Precious davidp at preshweb.co.uk
Tue Jul 15 14:31:57 BST 2014


On Tue, 15 Jul 2014 02:26:30 +0000
"Tappin, Chris (AU - Sydney)" <ctappin at deloitte.com.au> wrote:

> Hi Dancer users
> 
> I hope you can help me.  I'm pretty new to Dancer and I'm trying to
> write a simple web service for note taking.  The SimpleCRUD module
> looks perfect for my needs, but I need to add a timestamp to the
> record that SimpleCRUD creates.
> 
> From the documentation I assume the right way to do this is with the
> 'add_edit_row_pre_save' hook, but the code in that sub doesn't seem
> to ever get called.

The first and most obvious check is that you have at least version 0.91
of Dancer::Plugin::SimpleCRUD installed - as that's the version the
add_edit_row_pre_save hook was first added in.

> simple_crud(
>       record_title => 'Log item',
>       prefix => '/crud',
>       db_table => 'prototype',
>       editable => 1,
> editable_columns => [ qw( UFirstName ULastName Details Type
> KFirstName KLastName Outcome ) ], add_edit_row_pre_save => sub {
>             my $row = shift;
>             open TESTOUTPUT, ">", "TEST.txt" or die "$!";
>             print TESTOUTPUT "hello";
>             close TESTOUTPUT;
> },
> );


That's not how you use it - it's a Dancer hook registered by the
plugin, so you use the normal Dancer hook syntax, e.g.:


hook add_edit_row_pre_save => sub {
    ...
};


> Does anyone have some sample code or tips on how to implement
> 'add_edit_row_pre_save' that they would be willing to share?  My
> Googling turned up nothing.

Hmm - looking at the docs, it's not at all clear that they're Dancer
hooks and use the normal Dancer syntax.  I'll try to address that!



-- 
David Precious ("bigpresh") <davidp at preshweb.co.uk>
http://www.preshweb.co.uk/     www.preshweb.co.uk/twitter
www.preshweb.co.uk/linkedin    www.preshweb.co.uk/facebook
www.preshweb.co.uk/cpan        www.preshweb.co.uk/github




More information about the dancer-users mailing list