[Dbix-class] DBIx::Class field metadata and validation

John Siracusa siracusa at gmail.com
Sat Jul 30 01:23:27 CEST 2005

On 7/29/05 4:30 PM, Dan Kubb wrote:
> I've got an idea on how DBIx::Class could handle field metadata
> and validation and I wanted to get some input on it [...]
>    - Field classess can inherit from one or more classes that
>      define the metadata and validation rules for a specific type
>      of data.  For example, there might be a Type class for strings,
>      which provides properties like length_min, length_max, format
>      (for a regex the column values must match), etc. [...]
> The one thing I'm really not sure about is that I've made it so
> each column value is a blessed scalar in its Field class. That
> way the data is stored, but I can easily get at the property
> values if there are needed.  I'm concerned about performance and
> memory usage though, although it allows you to do nice things
> like this once an object is instantiated:
>    # get the maximum length for the field
>    my $length_max = $obj->name_first->length_max;

You might want to peek at this to see a similar design in action:


My approach is slightly different in that the object attributes are not
objects themselves.  Instead, there are metadata objects for each column
(and table and so on).  After all, each instance of a row in a given table
is going to have the same constraints on it.

The example above, for instance, looks like this instead:


and note that $obj1->meta is the same as $obj2->meta, and so on; the
metadata is a per-class singleton.  This saves on memory and reduces
per-object complexity bloat.


More information about the Dbix-class mailing list