[Dbix-class] modfiying data on retrieval

Ash Berlin ash_cpan at firemirror.com
Mon Mar 5 14:57:38 GMT 2007


Dave Howorth wrote:
> Will Hawes wrote:
>> On 05/03/07, Dave Howorth <dhoworth at mrc-lmb.cam.ac.uk> wrote:
>>> I need to read data from a database where fields have been entered by
>>> hand and have miscellaneous extraneous leading and trailing whitespace.
>>>
>>> I think the best approach is to suppress these characters as I retrieve
>>> the fields from the database, so I guess I need to override some method
>>> (in my Schema ?) but I haven't figured out which.
>>>
>>> I've looked around in the Cookbook and FAQ without spotting anything.
>>> Could somebody give me a pointer to the right place?
>>>
>>> Thanks, Dave
>> Wouldn't you just override the relevant accessors in your model
>> classes to do this?
> 
> I'm not quite sure what 'model classes' means in this context? I don't
> think I want to override individual accessors; I think I want to
> override whatever they inherit from (the equivalent of CDBI's get()
> method). I just don't know where to read up about how to do that.
> 
> Cheers, Dave
> 


If you really want to do it that way - look at Inflators.

What Will was talking about was adding something like the following:

sub my_col {
   my ($self) = shift;

   if (@_)
     return my_trim($self->next::my_col);

   $self->next::my_col(my_trim(@_));
}


In your ResultSource classes.

Ash



More information about the Dbix-class mailing list