Subject: | Use defined() to check for Result object existance |
If a Result object has overloaded the "" operators (stringification)
with fallback, then evaluating it in boolean context may cause the
overload method to fire unnecessarily. And that method could actually
return a false value, even though the object does exist. Using the
defined() operator prevents this.
I've attached a patch that addresses the one incident that I've found so
far. There may be others, and I'll submit more patches if I stumble
into them.
Thanks for the great work!
-Jeff
Subject: | DBIx-Class-0.08196.patch |
diff -Naur DBIx-Class-0.08196/lib/DBIx/Class/Row.pm DBIx-Class-0.08196.mine/lib/DBIx/Class/Row.pm
--- DBIx-Class-0.08196/lib/DBIx/Class/Row.pm 2011-11-28 21:15:48.000000000 -0800
+++ DBIx-Class-0.08196.mine/lib/DBIx/Class/Row.pm 2012-05-18 14:18:13.000000000 -0700
@@ -315,10 +315,10 @@
my $existing;
# if there are no keys - nothing to search for
- if (keys %$them and $existing = $self->result_source
+ if (keys %$them and defined ($existing = $self->result_source
->related_source($relname)
->resultset
- ->find($them)
+ ->find($them))
) {
%{$rel_obj} = %{$existing};
}