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

Rob Kinyon rob.kinyon at gmail.com
Thu Mar 5 17:17:26 GMT 2009


On Thu, Mar 5, 2009 at 12:07, David Ihnen <davidi at norchemlab.com> wrote:
> 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.

So, the following are different:
    my $x = $rs->method;
    my ($y) = $rs->method;

That's sucky.

> 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...

Context-awareness, while cool, is kinda like operator overloading and
monkeypatching. It's something you should have in that section of your
toolbox that has the "Write 500 words as to why you should be allowed
to use me" essay requirement.

Rob



More information about the DBIx-Class mailing list