The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Smolder::Constraints

SYNOPSIS

    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),
        }
    };

DESCRIPTION

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.

ROUTINES

email

Returns a method which validates an email address

unsigned_int

Returns regex that assures the data is simply an unsigned integer

bool

Returns a regex that assures the data is either a '1' or a '0'

length_max

Given an integer $max, returns a regex that assures the data has at most $max number of printable characters.

length_min

Given an integer $min, returns a regex that assures the data has at least $min number of printable characters.

length_between

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.

enum_value

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');

unique_field_value

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)

existing_field_value

Returns a sub that will verifiy that a value exists in a particular table in a particular column.

    existing_field_value('developer', 'id')

file_mtype

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'),

smoke_report_tags

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()