[Dbix-class] Inflation and Deflation
fREW Schmidt
frioux at gmail.com
Thu Jun 11 15:30:10 GMT 2009
>
>
> 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) =3D @_;
> #if called without columns to pass to JSON, use all of them
> @cols =3D keys %{ $self->get_columns };
>
> return JSON::Any->objToJson({ map { $_ =3D> $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.
Eh, I have always thought that what I'd like to do is this:
__PACKAGE->add_columns(
username {
json =3D> 1,
},
street_address {
json =3D> 1,
});
And then the TO_JSON method would just return:
{ username =3D> $self->username, street_address =3D> $self->street_address }
You can set the JSON class to automatically call the TO_JSON method, which
is pretty convenient in these cases.
Anyway, I'm probably *not* really talking about an inflator as the given
items keep their same methods.
-- =
fREW Schmidt
http://blog.afoolishmanifesto.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20090611/4e3=
8bc9c/attachment.htm
More information about the DBIx-Class
mailing list