On 5/2/07, Ovid <[EMAIL PROTECTED]> wrote:
> This may or may not be of use to anyone. One thing I've done is create
> a 'datatype generator' which is shorthand for many data types and it's
> legible, too. For example, instead of this:
>
> reason => {
> type => 'scalar',
> length => 255,
> default => '',
> not_null => 1,
> lazy => 1,
> },
>
> I can write this:
>
> reason => SCALAR( 255, DEFAULT '', NOT_NULL, LAZY ),
Cute :)
> Anyone see problems with this approach?
Seems like a valid (if odd, IMO :) dose of syntactic sugar. My one
piece of advice I can give is to pull the list of type names and valid
attributes for each type from Rose::DB::Object::Metadata itself (or
rather, from the current class's meta_class, if possible) using the
column_type_classes() method. Example:
my $map = Rose::DB::Object::Metadata ->column_type_classes;
..or...
my $map = MyDBObject->meta_class->column_type_classes;
and then:
while(my($type, $class) = each %$map)
{
# $type is "scalar" or whatever, and $class is some
# Rose::DB::Object::Metadata::Column::* class name.
...
# Auto-generate ALLCAPS methods here, maybe checking if
# $class->can('someattr') to find out if an attr is
# applicable.
}
Something like that, anyway. Basically, avoid hard-coding the list of
type names or attr names.
-John
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Rose-db-object mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rose-db-object