Mark Stosberg > Data-FormValidator-FromDBI > Data::FormValidator::FromDBI

Download:
Data-FormValidator-FromDBI-0.04_01.tar.gz

Dependencies

Annotate this POD

Module Version: 0.04_01   Source  

INTERNAL DOCUMENTATION ^

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.

_add_type_constraints()

   _add_type_constraints($dfv_profile,$name,$type_num,$type_name);

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

NAME ^

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

SYNOPSIS ^

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

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

DESCRIPTION ^

 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$/

TODO ^

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

EXPORT

generate_profile

SEE ALSO ^

Data::FormValidator

CONTRIBUTING ^

Patches, questions and feedback are welcome. This project is maintained using darcs ( http://www.darcs.net/ ). My darcs archive is here: http://mark.stosberg.com/darcs_hive/dfv-fromdbi/

AUTHOR ^

Mark Stosberg, <mark@summersault.com>

COPYRIGHT AND LICENSE ^

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: