missing the point about mapping from database to object to external rep

[prev] [thread] [next] [Date index for 2004/12/03]

From: merlyn (Randal L. Schwartz)
Subject: missing the point about mapping from database to object to external rep
Date: 21:29 on 03 Dec 2004
OK, I'm staring at the implementations of ->has_a and ->add_trigger,
and I figure I'm either just not understanding how this works, or I'm
doing something wrong or the hard way.

Here's what I want to do:

__PACKAGE__->is_a_date(qw(start_date end_date));

where My::Top::Level::CDBI::Class::is_a_date is

sub is_a_date {
  my $class = shift;
  for my $column (@_) {
    ## something here
  }
}

the "something here" needs to grab the database output and interpret into
a Time::Piece, and do the reverse when updating the database.  This is the
example under has_a for inflate/deflate.

But also, while I'm setting the value, I want to be able to say:

        My::Event->create({ start_date => '11/22/04', end_date => '12/1/04'})

and have it trigger *some* code to turn those values into Time::Piece,
maybe with a few variant input forms.

normalize_column_values doesn't cut it, because that's not per-column.
before_set_start_date doesn't cut it, because there's no way to return a
Time::Piece from the trigger.

Am I just missing something?  How are other people handling this?

        -- 
        Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@xxxxxxxxxx.xxx> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

(message missing)

missing the point about mapping from database to object to external rep
merlyn (Randal L. Schwartz) 21:29 on 03 Dec 2004

Generated at 15:37 on 08 Dec 2004 by mariachi v0.52