NAME

Handel::Components::Constraints - Column constraints for schemas

SYNOPSIS

package MySchema::Table;
use strict;
use warnings;
use base /DBIx::Class/;

__PACKAGE__->load_components('+Handel::Component::Constraints');
__PACKAGE__->add_constraint('myconstraint', 'foocolumn' => \&mysub);

1;

DESCRIPTION

Handel::Components::Constraints is a simple way to validate column data during inserts/updates using subroutines. It mostly acts as a compatibility layer for add_constraint used in Class::DBI.

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.

METHODS

add_constraint($name, $column, \&sub)

Adds a constraint for the specified column.

Note: Always use the real column name in the database, not the accessor alias for the column.

check_constraints

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;
    };
};
value

The value of the column to be checked.

source

The source storage object for the row being updated/inserted.

column

The name of the column being checked.

data

A hash reference containing all of the columns and their values. Changing and values in the hash will also change the value interested/updated in the database.

AUTHOR

Christopher H. Laco
CPAN ID: CLACO
claco@chrislaco.com
http://today.icantfocus.com/blog/