Re: inflating columns to objects

[prev] [thread] [next] [Date index for 2004/10/27]

From: Drew Taylor
Subject: Re: inflating columns to objects
Date: 14:13 on 27 Oct 2004
On Wed, 27 Oct 2004 14:24:26 +0100, Dave Howorth
<dhoworth@xxxxxxx.xxx.xx.xx> wrote:

> Since you're
> interested, what I'm trying to do is format the string into fixed length
> lines (not whatever width the widget happens to be). Then I want to put
> numbers at the start and end of the line indicating the character
> position in the string. It's a common way to present biological
> sequences. I hope that clears up that confusion.

Ahhh, I see now. Sorry for being thick headed. :-)

> > As for how to inflate something it's very simple:
> >
> > MyClass->columns(Essential=>qw(...my_col...));
> > MyClass->has_a(my_col => MyInflator, inflate=>\&MyInflator::inflate);
> > # the subref can be located in any package - just use a fully
> > qualified function name
> >
> > package MyInflator;
> >
> > sub inflate {
> >   my $value = shift;
> >   # format it...
> >   return $formatted;
> > }
> 
> OK, this is an alternative style of definition. When I substitute this
> code for my code, I see the following changes:
> 
>    - the inflate method does get called (in my code, my display method
>      followed by my new method got called), but
>    - the string that is displayed on the Maypole list page is the
>      original string, not the 'inflate'd one (in my code it was the
>      'display'ed string).
>    - there IS now a string displayed on the edit page (i.e the AsForm
>      generated text) but it too is the original database string (in my
>      code, there's no widget at all.)
> 
> So this doesn't get the modified text on the page at all :(  I guess the
> reason is not because you used a different style of setting up the
> inflate method, but because you didn't overload stringification. Your
> method causes the formatted text to be stored in the object, whereas
> mine stores the database string and formats on output.

Ahhh... stringification. By default CDBI uses the primary key(s) when
stringified, but that is configurable.

# the easy way
Widget->columns(Stringify => qw/your_col/);

# the more powerful way
sub stringify_self {
  my $self = shift;
  return join ":", $self->id, $self->name;
}

See the "OVERLOADED OPERATORS" section of the docs for more details.
It sounds like you just need to rename your display() method to
stringify_self() and CDBI will stringify using that method. Hope this
helps. Sounds like we're getting close.

Drew
        -- 
        ----------------------------------------------------------------
 Drew Taylor                 *  Web development & consulting
 Email: drew@xxxxxxxxxx.xxx  *  Site implementation & hosting
 Web  : www.drewtaylor.com   *  perl/mod_perl/DBI/mysql/postgres
 ----------------------------------------------------------------

(message missing)

inflating columns to objects
Dave Howorth 16:23 on 26 Oct 2004

Re: inflating columns to objects
Drew Taylor 16:30 on 26 Oct 2004

Re: inflating columns to objects
Dave Howorth 16:41 on 26 Oct 2004

Re: inflating columns to objects
Drew Taylor 17:40 on 26 Oct 2004

Re: inflating columns to objects
Dave Howorth 13:24 on 27 Oct 2004

Re: inflating columns to objects
Drew Taylor 14:13 on 27 Oct 2004

Re: inflating columns to objects
Dave Howorth 14:33 on 27 Oct 2004

Re: inflating columns to objects
Drew Taylor 14:37 on 27 Oct 2004

Re: inflating columns to objects
Dave Howorth 16:17 on 27 Oct 2004

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52