[Dbix-class] [RFC] Form validation component for DBIx::Class

Adam Paynter adampaynter at gmail.com
Fri Aug 18 16:36:06 CEST 2006


Hello all,

For those of you who do not know me, my name is Adam Paynter. I work as a
web applications developer for an organization who has chosen Perl as its
language of choice and DBIx::Class as its ORM of choice. We deal heavily
with web-based information systems which obviously require data validation.

For our purposes, I have developed DBIx::Class::FormValidator (not available
on CPAN, but I have attached the .pm file) to make data validation a tightly
integrated feature of our DBIx::Class classes. However, I only realized
recently that DBIx::Class::Validation (available on CPAN) already exists.
Both share some common features, but I believe FormValidator serves a
different purpose than Validation does. Therefore, I am requesting your
comments regarding the future of FormValidator (whether I should publish it
anyway, etc...).

First of all, let my begin by saying that both FormValidator and Validation
center around data validation packages such as Data::FormValidator. If you
are unfamiliar with Data::FormValidator, chances are you are not going to
understand the features of these two components. You have been warned.

As mentioned before, I have attached the package's .pm file to this message.
I strongly suggest looking at the synopsis to get a feel for its behaviour.

DBIx::Class::Validation (currently on CPAN) offers automatic validation of
data, prior to any actions taking place at the storage layer. This is
accomplished by overriding the insert and update methods. A validation
profile provided by the author of a DBIx::Class package serves as the basis
for its data validation constraints.

Likewise, DBIx::Class::FormValidator (currently in my SVN repository) offers
automatic validation of data, prior to any actions taking place at the
storage layer. However, it differs in the fact that its validation profile
is automatically generated, based upon the column definitions of the
DBIx::Class package in question. This process takes into consideration
almost all attributes which may be defined for a column, including
data_type, size, is_nullable and is_auto_increment, among others. Additional
constraints may easily be added to the column definitions, as described in
the documentation.

Some examples :
- Values pertaining to a column marked as nullable will be optional
- Values pertaining to a column marked as auto increment will be optional
- Values pertaining to a column marked as non-nullable will be required
(there are exceptions, such as auto incremented columns, default values,
etc...)
- Values pertaining to a column whose type is varchar(67) will be restricted
to 67 characters.
- Values pertaining to a column whose type is float will be restricted to
the appropriate floating point number regular expression as provided by
RegExp::Common

The algorithm is described in the documentation. With this in mind,
DBIx::Class::FormValidator produces a sensible data validation profile which
would be of much use to external code wishing to handle the validation
process itself, rather than the ORM. Such a situation is common within our
applications. In fact, the ORM's ability to validate data automatically when
inserting or updating came as an after-thought. We are much more interested
in the ability to have a sensible data validation profile automatically
generated for us.

As well, DBIx::Class::FormValidator is capable of accepting
Data::FormValidator::Results objects in most of its methods where HASH
references are traditional expected. For example, the create method, when
given a Data::FormValidator::Results object, will automatically glean only
the pertinant data from it and proceeding on as usual. Other methods
conforming to this behaviour include update and create_related.

Any comments or suggestions regarding what I should do will be greatly
appreciated. Thanks for your time!

- Adam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/dbix-class/attachments/20060818/7533e011/attachment-0001.htm 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: FormValidator.pm
Type: application/octet-stream
Size: 24526 bytes
Desc: not available
Url : http://lists.rawmode.org/pipermail/dbix-class/attachments/20060818/7533e011/attachment-0001.obj 


More information about the Dbix-class mailing list