Giter Site home page Giter Site logo

dbix-class-validation-tweak's Introduction

NAME
    DBIx::Class::Validation - Validate all data before submitting to your
    database.

SYNOPSIS
    In your base "DBIx::Class" package:

      __PACKAGE__->load_components(qw/... Validation/);

    And in your subclasses:

      __PACKAGE__->validation(
        module => 'FormValidator::Simple',
        profile => { ... },
        filter => 0,
        auto => 1,
      );

    And then somewhere else:

      eval{ $obj->validate() };
      if( my $results = $EVAL_ERROR ){
        ...
      }

METHODS
  validation
      __PACKAGE__->validation(
        module => 'FormValidator::Simple',
        profile => { ... },
        filter => 0,
        auto => 1,
      );

    Calls "validation_module", "validation_profile" and "validation_auto" if
    the corresponding argument is defined.

  validation_module
      __PACKAGE__->validation_module('Data::FormValidator');

    Sets the validation module to use. Any module that supports a check()
    method just like "Data::FormValidator"'s can be used here, such as
    "FormValidator::Simple".

    Defaults to FormValidator::Simple.

  validation_profile
      __PACKAGE__->validation_profile(
        { ... }
      );

    Sets the profile that will be passed to the validation module. Expects
    either a HASHREF or a reference to a subroutine. If it's a subref it
    will be passed the result row object as it's first parameter so that you
    can perform complex data validation for cases when you'd like to have
    access to the actual result.

    For example, you could use the following to return an error if the named
    field is not unique in the table:

        my $profile = sub {
            my $result = shift @_;
    
            return {
                required => [qw/email/],
                constraint_methods => {
                    email => sub {
                        my ($dvf, $val) = @_;
                        return $result->result_source->resultset->find({email=>$val}) ? 0:1;
                    },
                },
            };
        };

    Please note that the subref needs to return a hashref/arrayref suitable
    for use in the validation module you have chosen.

  validation_auto
      __PACKAGE__->validation_auto( 1 );

    Turns on and off auto-validation. This feature makes all UPDATEs and
    INSERTs call the "validate" method before doing anything.

    The default is for validation_auto is to be on.

  validation_filter
      __PACKAGE__->validation_filter( 1 );

    Turns on and off validation filters. When on, this feature will make all
    UPDATEs and INSERTs modify your data to that of the values returned by
    your validation modules "check" method. This is primarily meant for use
    with "Data::FormValidator" but may be used with any validation module
    that returns a results object that supports a "valid()" method just like
    "Data::FormValidator::Results". (The "valid()" method must return an ARRAY
    reference or HASH reference.)

    Filters modify your data, so use them carefully.

    The default is for validation_filter is to be off.

  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.

EXTENDED METHODS
    The following "DBIx::Class::Row" methods are extended by this module:-

    insert
    update

SEE ALSO
    "DBIx::Class", "FormValidator::Simple", "Data::FormValidator"

AUTHOR
    Aran C. Deltac <[email protected]>

CONTRIBUTORS
    Tom Kirkpatrick <[email protected]>

    Christopher Laco <[email protected]>

    John Napiorkowski <[email protected]>

    Sergio Salvi <[email protected]>

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

dbix-class-validation-tweak's People

Contributors

kwakwaversal avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.