[Dbix-class] Inflation and Deflation

Jose Luis Martinez jlmartinez-lists-dbix at capside.com
Wed Jun 10 22:28:05 GMT 2009


fREW Schmidt escribió:
> 
> Very cool!  you may want to consider allowing the use of a TO_JSON 
> method as an alias to serialized.  At least for JSON stuff that's the 
> standard.  I will probably try this out tomorrow or the next day and 
> I'll let you know how it goes.

Thanks! You choose the method, as the column "serialized" is the column 
name that stores data structures in JSON format.

> fREW Schmidt
> http://blog.afoolishmanifesto.com

Reading through your blog, I found this entry:
http://blog.afoolishmanifesto.com/archives/739

Maybe you're confusing my module with something that can give you a JSON 
string from a DBIC row object. I have a couple of ideas for this one:

package DBIx::Class::Serializer::ToJSON;

use JSON::Any;

sub TO_JSON {
   my ($self, @cols) = @_;
   #if called without columns to pass to JSON, use all of them
   @cols = keys %{ $self->get_columns };

   return JSON::Any->objToJson({ map { $_ => $self->$_ } @cols });
}

1;

Then you load Serializer::ToJSON in the load_components of your DBIC 
Classes, and you get for free a TO_JSON method for all the row objects 
you apply it to. Maybe that is what you where looking for? (note: I've 
written this code as it was coming out... no testing)

Another idea is to take ResultClass::HashRefInflator and convert it into 
a ResultClass::JSONInflator... But that seems like an overkill, maybe.

Jose Luis Martinez
jlmartinez at capside.com



More information about the DBIx-Class mailing list