<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">        # 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 class="" style="white-space:pre">        </span>my $class = shift;</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">        </span>my $result = DBIx::Class::ResultClass::HashRefInflator-&gt;inflate_result(@_);</font></div><div><font face="monospace, monospace"><span class="" style="white-space:pre">        </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 class="" style="white-space:pre">        </span>my $self = shift;</font></div></div><div><div><font face="monospace, monospace"><span class="" style="white-space:pre">        </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>