NAME

Interchange6::Schema::Component::Validation

SYNOPSIS

package My::Result;

__PACKAGE__->load_components(qw(
  +Interchange6::Schema::Component::Validation
));

sub validate {
  my $self = shift;
  my $schema = $self->result_source->schema;

  unless ( $self->some_column =~ /magic/ ) {
    $schema->throw_exception("some_column does not contain magic");
  }
}

DESCRIPTION

This component allows validation of row attributes to be deferred until other components in the stack have been called. For example you might want to have the TimeStamp component called before validation so that datetime columns with set_on_create are defined before validation occurs. In this case your local_components call might look like;

__PACKAGE__->load_components( qw(TimeStamp +Interchange6::Schema::Component::Validation) );

In order to fail validation the "validation" method must throw an exception.

METHODS

validate

Called before insert or update action. Method should be overloaded by class which load this component. Validation failures should result in DBIx::Class::Schema::throw_exception being called.

insert

Overload insert to call "validate" before insert is performed.

update

Overload update to call "validate" before update is performed.