[Dbix-class] Set a resultset_class for a result_class from within a component loaded by the result_class

David Ihnen davidi at norchemlab.com
Thu Mar 5 17:07:52 GMT 2009


For these purposes I found this sneaky little ResultSetManager extension.

You put ResultSetManager in your load_components and you put your custom 
plugin for resultset into a load_resultset_components call.  An example 
from one of my classes.

__PACKAGE__->load_components(qw/IVRSchedule PK::Auto 
InflateColumn::DateTime ResultSetManager Core/);
__PACKAGE__->load_resultset_components(qw/Nothing/);

Nothing is actually a plugin that impliments the 'Nothing' design 
pattern - that is - instead of returning null when referencing a row in 
an empty resultset (particularly ->single and ->first, which I use many 
times when NOT looping over results, hence resulting in undef 
dereference errors on empty) it instead returns a magical 'Nothing' 
object which has characteristics like - (->is_nothing === 1, ->id === 0, 
@list = $rs->method === (), $row = $rs->method === bless({}, Nothing).  
The result - no need to if-then on empty resultsets when grabbing data. 

I wanted to use the Want module to change the return considering the 
context called in, but that module is, sadly, not compatible with 
mod_perl.  If it was, I could give back undefined, blessed ref, array 
ref, or hash ref depending on its context, which would be cool.  Dang 
segfaults...

David


Ashley wrote:
> I'm trying to do a custom component which requires an elaborate result 
> set. This is a component which might be of benefit to many projects if 
> I can get it together.
>
> I am writing it with its accompanying resultset_class but I cannot 
> seem to work out how to get the resultset_class loaded without 
> manually putting it into the "user" schema/row/table file/code. I have 
> played around with about 100 permutations of loading components or raw 
> parent classes in the component class to expose things like 
> _source_handle and resultset_class public and private friends, and 
> things like __PACKAGE__->set_component_class("resultset_class", 
> "DBICx::ResultSet::MyRS"). I can't seem to nail it down and when I 
> thought I might have something with the ::DB component, I got a big 
> ol'deprecation notice.
>
> So, how do I set the resultset_class for a result_class from within a 
> component which is loaded from the result_class? I'm sure I'm missing 
> something.
>
> Thanks!
> -Ashley
>
>
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: 
> http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
>




More information about the DBIx-Class mailing list