Handel::Components::Constraints - Column constraints for schemas
package MySchema::Table; use strict; use warnings; use base qw/DBIx::Class/; __PACKAGE__->load_components('+Handel::Component::Constraints'); __PACKAGE__->add_constraint('column', 'Constraint Name' => \&checker); 1;
Handel::Components::Constraints is a simple way to validate column data during inserts/updates using subroutines. It mostly acts as a compatibility layer for subclasses that used add_constraint when Handel used Class::DBI.
add_constraint
There is no real reason to load this component into your schema table classes directly. If you add constraints using Handel::Storage->add_constraint, this component will be loaded into the appropriate schema source class automatically.
Adds a named constraint for the specified column.
__PACKAGE__->add_constraint('quantity', 'Check Quantity' => \%check_qty);
Note: Always use the real column name in the database, not the accessor alias for the column.
This loops through all of the configured constraints, calling the specified \&sub. Each sub will receive the following arguments:
sub mysub { my ($value, $source, $column, \%data) = @_; if ($value) { return 1; } else { return 0; }; };
The value of the column to be checked.
The result object for the row being updated/inserted.
The name of the column being checked.
A hash reference containing all of the columns and their values. Changing any values in the hash will also change the value inserted/updated in the database.
Calls check_constraints and then inserts the row. See "insert" in DBIx::Class::Row for more information about insert.
check_constraints
Calls check_constraints and then updates the row. See "update" in DBIx::Class::Row for more information about update.
Christopher H. Laco CPAN ID: CLACO claco@chrislaco.com http://today.icantfocus.com/blog/
To install Handel, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Handel
CPAN shell
perl -MCPAN -e shell install Handel
For more information on module installation, please visit the detailed CPAN module installation guide.