DBIx-Class-Validation

 view release on metacpan or  search on metacpan

lib/DBIx/Class/Validation.pm  view on Meta::CPAN

with L<"Data::FormValidator"> but may be used with any validation module
that returns a results object that supports a C<valid()> method just
like L<"Data::FormValidator::Results">.

B<Filters modify your data, so use them carefully>.

The default is for validation_filter is to be off.

=head2 validate

  $obj->validate();

Validates all the data in the object against the pre-defined validation
module and profile.  If there is a problem then a hard error will be
thrown.  If you put the validation in an eval you can capture whatever
the module's check() method returned.

=cut

sub validate {
    my $self = shift;
    my %data = $self->get_columns;
    my $module = $self->validation_module;
    my $profile = $self->validation_profile;

    if (ref $profile eq 'CODE') {
        $profile = $profile->($self);
    };
    my $result = $module->check( \%data => $profile );

    if ($result->success) {
        if ($self->validation_filter && $result->can('valid')) {
            $self->$_($result->valid($_)) for ($result->valid);
        };
        return $result;
    } else {
        croak $result;
    };
};

=head1 EXTENDED METHODS

The following L<"DBIx::Class::Row"> methods are extended by this module:-

=over 4

=item insert

=cut

sub insert {
    my $self = shift;
    $self->validate if $self->validation_auto;
    $self->next::method(@_);
}

=item update

=cut

sub update {
    my $self = shift;
    my $columns = shift;

    $self->set_inflated_columns($columns) if $columns;
    $self->validate if $self->validation_auto;
    $self->next::method(@_);
};

1;
__END__

=back

=head1 SEE ALSO

L<"DBIx::Class">, L<"FormValidator::Simple">, L<"Data::FormValidator">

=head1 AUTHOR

Aran C. Deltac <bluefeet@cpan.org>

=head1 CONTRIBUTORS

Tom Kirkpatrick <tkp@cpan.org>

Christopher Laco <claco@cpan.org>

John Napiorkowski <jjn1056@yahoo.com>

Sergio Salvi <sergio@developerl.com>

=head1 LICENSE

You may distribute this code under the same terms as Perl itself.



( run in 2.943 seconds using v1.01-cache-2.11-cpan-d06a3f9ecfd )