Smolder::Constraints
use Smolder::Constraints qw(email unsigned_int max_length); # then in a D::FV profile my $form = { required => [qw(email id last_name)], constraint_methods => { email => email(), id => unsigned_int(), last_name => max_length(255), } };
This package provides/exports several routines that are useful inside of Smolder for form validation, using Data::FormValidator. Each routine will return something suitable for use inside of a constraint_methods hash.
constraint_methods
Returns a method which validates an email address
Returns regex that assures the data is simply an unsigned integer
Returns a regex that assures the data is either a '1' or a '0'
Given an integer $max, returns a regex that assures the data has at most $max number of printable characters.
Given an integer $min, returns a regex that assures the data has at least $min number of printable characters.
Given an integer $min and an integer $max, returns a regex that assures the data has at least $min and at most $max number of printable characters.
Returns a method which will make sure that the value is an allowable enum value for the given table and column.
enum_value('table', 'column');
Returns a method which will make sure that the value being updated does not currently exist in the table and field specified. Can be passed an optional integer value which is used as the table's primary id to not compare against (this is useful when editing an existing row when you don't care it still has the same value or not).
unique_field_value('project', 'name')
or
unique_field_value('developer', 'username', 23)
Returns a sub that will verifiy that a value exists in a particular table in a particular column.
existing_field_value('developer', 'id')
Returns a sub that will validate that the file is one of the given MIME types. If it is valid, it will return the name of the temporary file currently being used.
file_mtype('text/plain', 'image/jpg'),
Returns a sub that will verifiy that a value is a comma separated list of tags that are no more than 255 characters each. If they are valid, then an array ref of the tags will be returned.
smoke_report_tags()
To install Smolder, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Smolder
CPAN shell
perl -MCPAN -e shell install Smolder
For more information on module installation, please visit the detailed CPAN module installation guide.