Peter Rabbitson wrote:
David Ihnen wrote:
When working with the null pattern classes from Mr. Rabbitson, I
discovered this slight ommission that results in getting an undefined,
when you're actually wanting a null.  That is, even when something is
not true, I still want it!  It should be entirely backwards compatible
with existing code.  Perhaps it can it make it into the next version?

Hopefully,

David



--- /usr/share/perl5/DBIx/Class/Relationship/Accessor.pm    2009-03-10
17:19:39.000000000 -0700
+++ DBIx/Class/Relationship/Accessor.pm    2009-03-10 17:13:52.000000000
-0700
@@ -25,7 +25,7 @@
        return $self->{_relationship_data}{$rel};
      } else {
        my $val = $self->find_related($rel, {}, {});
-        return unless $val;
+        return $val unless $val;
        return $self->{_relationship_data}{$rel} = $val;
      }
    };


Thank you for spotting this omission. Unfortunately your patch can not be
applied, as it changes $row->relaccessor behavior in a subtle way. Here is
what was committed instead, which should solve the problem equally well:

http://dev.catalyst.perl.org/svnweb/bast/revision/?rev=5734

Cheers
Hmm. Indeed you have a point for that subtle behavior. I wonder if it could be return wantarray ? () : $val unless $val; - enforcing the semantic that a false result is an empty list, without caching the negative.

Which brings the question I'd have regarding it is that you are changing the semantics in a different subtle way... even though the result is nothing you are still storing it in the _relationship_data->rel field. The original line did *not* store an undef in this field to indicate "I looked and there is nothing there". I don't know the possible ramifications of this. Is that going to have any interesting side effects?

I would suppose if that _relationship_data->rel field is only relevant to the current instantiated resultset, it would not matter, and might be faster than iterating through the accessor/query logic again to get another null on subsequent accesses?

David

_______________________________________________
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/[email protected]

Reply via email to