<div class="gmail_quote">On Thu, Aug 26, 2010 at 3:33 AM, Peter Rabbitson <span dir="ltr"><<a href="mailto:rabbit%2Bdbic@rabbit.us">rabbit+dbic@rabbit.us</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">Pavel A. Karoukin wrote:<br>
> Hello,<br>
><br>
> I am trying to make something work nice, but it doesn't want to =)<br>
> Probably, it's just by design, or I am missing something.<br>
><br>
</div><div class="im">> Question: is it possible to make it work with $user->data->{test} = 1;<br>
> notation? I.e. I do not want to create new methods in results class, not<br>
> want to extract hash from field first and then save it?<br>
<br>
</div>Absolutely impossible, since the whole idea of InflateColumn is:<br>
*) A plain scalar value supplied to new/update is assumed to be an<br>
already-deflated value to be placed directly in the database<br>
*) Any type of reference (blessed or not) is a candidate for deflation<br>
and passed on to the deflator<br>
<br>
However you may find that FilterColumn does exactly what you want to<br>
do.<br><br></blockquote><div><br></div><div>Peter,</div><div><br></div><div>Thank you for pointing to FilterColumn. I've tried it with almost same result tho.. Probably I am doing something wrong?</div><div><br></div>
<div>I.e. I replaced __PACKAGE__inflate_column with:</div><div><br></div><div>__PACKAGE__->filter_column(</div><div> 'data' => {</div><div> filter_to_storage => '__data_to_storage',</div>
<div>
filter_from_storage => '__data_from_storage',</div><div> },</div><div>);</div><div><br></div><div><br></div><div>sub __data_to_storage {</div><div> my ($self, $data) = @_;</div><div> return encode_json($data);</div>
<div>}</div><div><br></div><div>sub __data_from_storage {</div><div> my ($self, $data) = @_;</div><div> return decode_json($data);</div><div>}</div><div><br></div><div><br></div><div>And now in my controller code trying this:</div>
<div><br></div><div><div> $c->user->data->{test}; # return "yes" as stored in DB in JSON format</div><div> $c->user->data->{test} = "no"; # now this contain "no", but not stored in DB yet</div>
<div> $c->user->update(); # I thought it should pass $c->user->date to __data_to_storage(), but it never do this. Why?</div></div><div><br></div><div>So so far it behaive the same way as InflateColumn =(</div>
<div><br></div><div>Regads,</div><div>Pavel</div><div><br></div></div>