On 1/11/06 12:55 PM, Svilen Ivanov wrote:
> The last email John sent outlines the key steps for creating and
> handling new/custom columns. This is my effort to give you an example
> how I dealt with creating custom column.

Excellent!  Are you interested in starting a Rose/DB/Object/Extending.pod
document? :)

I have a few pointers and questions about your example.  In Metadata.pm:

    # override the blob type with custom storable
    my %map = __PACKAGE__->column_type_classes;
    $map{'blob'} = 'Fallery::Model::Rose::Metadata::Column::Storable';
    __PACKAGE__->column_type_classes(%map);

Is there a reason you didn't just do this?

  __PACKAGE__->column_type_class(blob => 'Fallery::...::Storable');

As for the UTF8 columns, I know I'm slacking on adding that feature to RDBO
proper...sorry :-/  It's On The List(tm).

In Metadata_Column_Storable.pm:

  Rose::Object::MakeMethods::Generic->make_methods
  (
    { preserve_existing => 1 },
    scalar => [ __PACKAGE__->common_method_maker_argument_names ]
  );

You don't need to do this at all in a column subclass unless you're actually
adding to the list of common_method_maker_argument_names.

...and even then, you can just add the methods for the names you do add.
What you copied and pasted is just me being lazy in my own code.  It tries
to create scalar methods for all common_method_maker_argument_names, and
will skip any that already exist.  I do it that way so I'm sure not to
forget to add a method for a one of the common_method_maker_argument_names.

Anyway, since you're not adding any, it's not needed at all and can be
deleted.

Next tip...

  foreach my $type (__PACKAGE__->available_method_types)
  {
    __PACKAGE__->method_maker_class($type => 'Fallery::...::Storable');
    __PACKAGE__->method_maker_type($type => 'storable');
  }

You may be surprised to learn that available_method_types contains more than
just get_set by default.  The types "get" and "set" are also in there.  Your
method maker has to handle them as well.  An easy way is to just change this
line in your method maker:

       if ( $interface eq 'get_set' ) {

To this:

       if ( $interface eq 'get_set' ||
            $interface eq 'get'     ||
            $interface eq 'set' ) {

since get_set implements all of the functionality of get and set.  Ideally,
you'd define custom-tailored get and set interfaces.  The "set" method
should croak if no args are passed, and the "get" method should croak if
args are passed.

I plan to make a Rose::DB::Object::GetSet, if only as a demo, to prove the
flexibility of the method-making system.  Besides, some people like
get_foo() and set_foo() and thing a multi-function foo() is a Bad Idea.  I
disagree, but I want RDBO to work for them too :)

-John




-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to