Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
then everything works fine. But, but when you attempt to chain together the method calls:my $s = constructor(); my $dbs = $s->dbs; my $r = $dbs->query($Q); my $h = $r->hashes;
the result is not the same - you get a dead object.my $s = constructor(); my $r = $s->dbs->query($Q);
The reason this happens is that on line 165 of Simple.pm there is an attempt to reduce the reference count by double-quoting the database handle related to the statement handle:
A fix that works for me is to simply remove the double quotes. Then all 3 test cases in the test program below work. So I guess my questions are:# $self is quoted on purpose, to pass along the stringified version, # and avoid increasing reference count. $st = bless { db => "$self", sth => $sth, query => $query }, 'DBIx::Simple::Statement'; $statements{$self}{$st} = $st;
personally, I don't understand why line 165 of Simple.pm looks the way it does. I asked Juerd about it and here is what he said:
And that makes no sense to me:> Also, is there a reason you didnt use Scalar::Util::Weaken instead o +f > quoting an object like that? I'm not entirely sure what the reason was in this specific case, but i +n the general case I think it's safer to just have a string, than to hav +e something that when copied does increase the refcount, and could still be destroyed when you didn't expect it yet. If all you need is somethi +ng to recognise the object when you see it, then keeping the entire objec +t around is just unnecessary bloat; bloat that could cause many hours of debugging.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: method chaining fails where separate method calls succeed in DBIx::Simple
by thenaz (Beadle) on Aug 04, 2011 at 18:08 UTC | |
by tye (Sage) on Aug 04, 2011 at 18:37 UTC | |
by metaperl (Curate) on Aug 10, 2011 at 20:13 UTC | |
by tye (Sage) on Aug 10, 2011 at 21:08 UTC | |
by metaperl (Curate) on Aug 16, 2011 at 16:17 UTC | |
| |
by Eliya (Vicar) on Aug 04, 2011 at 18:28 UTC |