View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Mark Stosberg > Data-FormValidator-FromDBI-0.04_01 > Data::FormValidator::FromDBI



Annotate this POD

Module Version: 0.04_01   Source  


The below documentation is provided for developers of this module only. These APIs may change without notice. Mere users of the module need to read no furter.



Modify $dfv_profile by reference by adding constraints for the field named $name by analyzing its related $type_num and $type_name.


Data::FormValidator::FromDBI - Generate FormValidator Profiles from DBI schemas


  use Data::FormValidator::FromDBI;
  my $profile = generate_profile($dbh,$table);

  # For human inspection.
  use Data::Dumper;
  print Dumper $profile;


 my $profile = generate_profile($DBH,$table);   

This routine takes a database handle and table name as input and returns a Data::FormValidator profile based on the constraints found in the database.

This could be used directly to avoid writing a validation profile in Perl at all. Or you could print out a copy of the result and modify it by hand to create an even more powerful validation profile.

For the moment it has only been tested some with PostgreSQL 8.0, but better support for other databases is desired. See the TODO list below.

Currently the following details are used to create the profile.

required and optional

Fields defined as "not null" will be marked as required. Otherwise they will be optional.

maximum length

For text fields, a constraint will be added to insure that the text does not exceed the allowed length in the database

type checking

boolean, and numeric types will be checked that their input looks reasonable for that type.

For date, time, and timestamp fields, a constraint will be generated to verify that the input will be in a format that Postgres accepts.

basic constraint parsing

One basic constraint is current recognized and transformed. If a field must match one of a predetermined set of values, it will be tranformed into an appropriate regular expression. In Postgres, this constraint may look like this:

 ((approval_state = \'needs_approval\'::"varchar") OR (approval_state = \'approved\'::"varchar"))

That will transformed into:

 approval_state => qr/^needs_approval|approved$/


 - Better support for more databases and database versions
 - Allow users to override date format strings
 - Allow users to override constraint messages






Patches, questions and feedback are welcome. This project is maintained using darcs ( ). My darcs archive is here:


Mark Stosberg, <>


Copyright 2003 by Mark Stosberg

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: