On 14 September 2011 19:12, Assaf Gordon <gordon@cshl.edu> wrote:
Hello Dancers,
I have another dancer-newbie question:
Is there a recommended way to verify input (or general variables) and report errors to the user ?
Common scenario: I have a form with 3 inputs, and they need to by in a certain format (verifiable by a simple regex). If the inputs do not conform, I want to:
1. Log the error for later inspection 2. Inform the user (e.g. using Plugin::Dancer::FlashMessage) (The error message reported to the user is not necessarily the same one written to the log, if I wish to include more technical details in the log, or be more descriptive and verbose to the user). 3. Stop processing the request.
And I wish to do it in the most 'fun' dancer kind of way.
Looking at a naive implementation (below), there's alot of redundant code for validating and reporting the error back to the user (and more validation code than actual processing code).
Any suggestions ?
Thanks! -gordon
I have been using Data::FormValidator, but recently Validate::Tiny has caught my attention and it seems to match Dancer's minimalist philosophy. Someone recently posted a plugin to the Dancer mailing list: https://github.com/kalgan/Dancer-Plugin-ValidateTiny