[CDBI] Call a has_a rel's inflate/deflate method explicitly.

Peter Speltz peterspeltz at gmail.com
Fri Nov 4 20:58:46 GMT 2005


On 11/4/05, Matt S Trout <d
> Looking at _deflated_column,
>
> $meta->args->{deflate};
>
> should do the trick.
>

Yep that works.  I was forgetting the "args" .  What made me curious
was my meta_info hash has "DUMMY" for  deflate and inflate methods
which I set to code refs.

Anyway, in case anyone is curious, I needed this (rather than just
saying $self->_attr($col) )  because I want to call a custom deflate
for text iputs when editing datetime columns.  Time::Piece stringifies
like localtime and it never passes the validatiton like that or is it
in an editable form.  So i specified the has_a like:

__PACKAGE__->has_a("created" => 'Time::Piece',
        inflate => sub { Time::Piece->strptime(shift, "%Y-%m-%d %T") },
        deflate => sub { my $tp = shift; return $tp->ymd.' '.$tp->hms; },
        deflate4input => sub { my $tp = shift; return $tp->ymd.' '.$tp->hms; },
);

Then hacked AsForm::_to_textfield , to check for object and
deflate4Input code ref.

Thanks, Matt.




More information about the ClassDBI mailing list