DBIx::Class::Valiant::Validator::SetSize - Verify a DBIC related resultset
package Example::Schema::Result::Person; use base 'Example::Schema::Result'; __PACKAGE__->load_components(qw/ Valiant::Result Core /); __PACKAGE__->table("person"); __PACKAGE__->add_columns( id => { data_type => 'bigint', is_nullable => 0, is_auto_increment => 1 }, username => { data_type => 'varchar', is_nullable => 0, size => 48 }, first_name => { data_type => 'varchar', is_nullable => 0, size => 24 }, last_name => { data_type => 'varchar', is_nullable => 0, size => 48 }, password => { data_type => 'varchar', is_nullable => 0, size => 64, }, ); __PACKAGE__->has_many( credit_cards => 'Example::Schema::Result::CreditCard', { 'foreign.person_id' => 'self.id' } ); __PACKAGE__->validates( credit_cards => ( set_size=>+{ skip_if_empty=>1, min=>2, max=>4 }, ) );
Validations on related resultsets. This constrains minimum / maximum sizes on the set and permits optional sets (where the min/max is only applied when the set has entries).
This validator supports the following attributes:
Skip validations if the resultset is empty. In this context empty means that you have zero records. Probably not that useful; yhou might actually want 'skip_if_blank' instead.
Allows you to skip validations if the resultset is blank. In this context blank means that you have not prefetched the relationship or loaded it in any way. 'blank' is different from 'has none'. You might for example want to skip size validations if you have not prefetched the relationship.
The minimum or maximum number of rows that the resultset can contain. Optional (but I suspect you'd set at least one otherwise why bother with this constraint?
Error messages associated with the 'min' or 'max' constraints. Defaults to 'too_few' or 'too_many' translation tags.
This validator supports the follow shortcut forms:
validates attribute => ( result_set => [1,4], ... );
Which is the same as:
validates attribute => ( result_set => { min => 1, max => 4, } );
This validator supports all the standard shared parameters: if, unless, message, strict, allow_undef, allow_blank.
if
unless
message
strict
allow_undef
allow_blank
Valiant, Valiant::Validator, Valiant::Validator::Each.
See Valiant
To install Valiant, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Valiant
CPAN shell
perl -MCPAN -e shell install Valiant
For more information on module installation, please visit the detailed CPAN module installation guide.