[Dbix-class] Inflation and Deflation
Matt S Trout
dbix-class at trout.me.uk
Thu Jun 11 13:33:10 GMT 2009
On Thu, Jun 11, 2009 at 12:28:05AM +0200, Jose Luis Martinez wrote:
> 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 });
> }
I'd suggest delegating to an _data_for_json method here - that way
people can subclass it to include rels or forcibly exclude specific
columns or whatever ...
--
Matt S Trout Catalyst and DBIx::Class consultancy with a clue
Technical Director and a commit bit: http://shadowcat.co.uk/catalyst/
Shadowcat Systems Limited
mst (@) shadowcat.co.uk http://shadowcat.co.uk/blog/matt-s-trout/
More information about the DBIx-Class
mailing list