<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Ignore me, -EINSUFFICIENTCAFFEINE. Of course you need to class the returned objects ...</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 9 April 2015 at 15:57, Will Crawford <span dir="ltr">&lt;<a href="mailto:billcrawford1970@gmail.com" target="_blank">billcrawford1970@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">You _should_ just be able to subclass the HRI class and add those methods (and pass { result_class =&gt; &#39;My::HRI::Subclass&#39; } in for the RS attributes). I haven&#39;t tested this, will do in a moment :)</div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On 9 April 2015 at 14:58, Lasse Makholm <span dir="ltr">&lt;<a href="mailto:lasse@unity3d.com" target="_blank">lasse@unity3d.com</a>&gt;</span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div>I&#39;m using DBIx::Class::ResultClass::HashRefInflator in some places where full row object inflation is too slow. That&#39;s fine.</div><div><br></div><div>What I&#39;d really like to do though, is bless the resulting hashrefs into a &quot;light weight&quot; result class that provides a few convenience methods but knows little to nothing about DBIx::Class.</div><div><br></div><div>Trying something like:</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><font face="monospace, monospace">my $rs = $schema-&gt;resultset(&#39;MyTable&#39;)-&gt;search(...);</font></div><div><font face="monospace, monospace">$rs-&gt;result_class(&#39;MyApp::Schema::DumbResult::MyTable&#39;);</font></div><div><font face="monospace, monospace">while (my $thingy = $rs-&gt;next) {</font></div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><span style="font-family:monospace,monospace;white-space:pre-wrap">        # do, do, do</span><font face="monospace, monospace"><br></font></div></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div><font face="monospace, monospace">}</font></div></div></blockquote><div><br></div><div>with something like:</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace, monospace">package MyApp::Schema::DumbResult::MyTable;</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">use strict;</font></div><div><font face="monospace, monospace">use warnings;</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">use DBIx::Class::ResultClass::HashRefInflator;</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">sub inflate_result</font></div><div><font face="monospace, monospace">{</font></div><div><font face="monospace, monospace"><span style="white-space:pre-wrap">        </span>my $class = shift;</font></div><div><font face="monospace, monospace"><span style="white-space:pre-wrap">        </span>my $result = DBIx::Class::ResultClass::HashRefInflator-&gt;inflate_result(@_);</font></div><div><font face="monospace, monospace"><span style="white-space:pre-wrap">        </span>return bless $result, $class;</font></div><div><font face="monospace, monospace">}</font></div><div><font face="monospace, monospace"><br></font></div><div><div><font face="monospace, monospace">sub TO_JSON</font></div></div><div><div><font face="monospace, monospace">{</font></div></div><div><div><font face="monospace, monospace"><span style="white-space:pre-wrap">        </span>my $self = shift;</font></div></div><div><div><font face="monospace, monospace"><span style="white-space:pre-wrap">        </span>return { %$self };</font></div></div><div><div><font face="monospace, monospace">}</font></div></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">1;</font></div></blockquote><div><br></div><div>...breaks for a variety of reasons it seems, because DBIx::Class wants to do things like setting a result source instance on the result object, etc...</div><div><br></div><div>Is there an (easy) make this work? Or is it just in general a horrible idea?<br></div><div><br></div><div>Of course I can just do:</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace, monospace">$rs-&gt;result_class(&#39;DBIx::Class::ResultClass::HashRefInflator&#39;);</font></div><div><span style="font-family:monospace,monospace">my @stuff = map { bless $_, </span><span style="font-family:monospace,monospace">MyApp::Schema::DumbResult::MyTable </span><span style="font-family:monospace,monospace">} $rs-&gt;all;</span></div><div><span style="font-family:monospace,monospace"><br></span></div></blockquote><div>...but the other way is more convenient...</div><div><br></div><div>Or is it more sane to subclass the ResultSet and override first(), all() and next() to set the result_class and bless the resulting hashrefs?</div><div><br></div><div>Any input appreciated?<br></div><div><br></div><div>/L</div><div><br></div><div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><br></div></blockquote></div></div>
<br></div></div>_______________________________________________<br>
List: <a href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class" target="_blank">http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class</a><br>
IRC: <a href="http://irc.perl.org#dbix-class" target="_blank">irc.perl.org#dbix-class</a><br>
SVN: <a href="http://dev.catalyst.perl.org/repos/bast/DBIx-Class/" target="_blank">http://dev.catalyst.perl.org/repos/bast/DBIx-Class/</a><br>
Searchable Archive: <a href="http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk" target="_blank">http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk</a><br></blockquote></div><br></div>
</blockquote></div><br></div>