<div dir="ltr">Hah! You're right! It does work.<div><br></div><div>It was just me failing to realize that the errors were actually thrown at load time, not inflate time. The problem is putting a "dumb" under MyApp::Schema::Result:: because DBIx::Class will try to load and initialize it as a normal result class during DBIx::Class::Schema->load_namespaces().<div><br></div><div>Putting the dumb result class outside the MyApp::Schema::Result:: namespace works just fine.</div><div><br></div><div>Thanks for your help both of you.</div><div><br></div><div>/L</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 9, 2015 at 5:34 PM, Dmitry L. <span dir="ltr"><<a href="mailto:dim0xff@gmail.com" target="_blank">dim0xff@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Strange. Your example just works for me.<br>
I tried it with DBIC example ( DBIx::Class::Manual::Example ) without<br>
any changes, just copy-paste.<br>
<br>
And yes, I use the latest DBIC.<br>
<div class="HOEnZb"><div class="h5"><br>
On 9 April 2015 at 16:58, Lasse Makholm <<a href="mailto:lasse@unity3d.com">lasse@unity3d.com</a>> wrote:<br>
> I'm using DBIx::Class::ResultClass::HashRefInflator in some places where<br>
> full row object inflation is too slow. That's fine.<br>
><br>
> What I'd really like to do though, is bless the resulting hashrefs into a<br>
> "light weight" result class that provides a few convenience methods but<br>
> knows little to nothing about DBIx::Class.<br>
><br>
> Trying something like:<br>
><br>
> my $rs = $schema->resultset('MyTable')->search(...);<br>
> $rs->result_class('MyApp::Schema::DumbResult::MyTable');<br>
> while (my $thingy = $rs->next) {<br>
><br>
> # do, do, do<br>
><br>
> }<br>
><br>
><br>
> with something like:<br>
><br>
> package MyApp::Schema::DumbResult::MyTable;<br>
><br>
> use strict;<br>
> use warnings;<br>
><br>
> use DBIx::Class::ResultClass::HashRefInflator;<br>
><br>
> sub inflate_result<br>
> {<br>
> my $class = shift;<br>
> my $result = DBIx::Class::ResultClass::HashRefInflator->inflate_result(@_);<br>
> return bless $result, $class;<br>
> }<br>
><br>
> sub TO_JSON<br>
> {<br>
> my $self = shift;<br>
> return { %$self };<br>
> }<br>
><br>
> 1;<br>
><br>
><br>
> ...breaks for a variety of reasons it seems, because DBIx::Class wants to do<br>
> things like setting a result source instance on the result object, etc...<br>
><br>
> Is there an (easy) make this work? Or is it just in general a horrible idea?<br>
><br>
> Of course I can just do:<br>
><br>
> $rs->result_class('DBIx::Class::ResultClass::HashRefInflator');<br>
> my @stuff = map { bless $_, MyApp::Schema::DumbResult::MyTable } $rs->all;<br>
><br>
> ...but the other way is more convenient...<br>
><br>
> Or is it more sane to subclass the ResultSet and override first(), all() and<br>
> next() to set the result_class and bless the resulting hashrefs?<br>
><br>
> Any input appreciated?<br>
><br>
> /L<br>
><br>
><br>
><br>
</div></div><span class="im HOEnZb">> _______________________________________________<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:<br>
> <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>
<br>
<br>
<br>
</span><span class="HOEnZb"><font color="#888888">--<br>
//wbr, Dmitry L.<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
_______________________________________________<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>
</div></div></blockquote></div><br></div>