DBR
view release on metacpan or search on metacpan
lib/DBR/ResultSet.pm view on Meta::CPAN
package DBR::ResultSet;
use strict;
use base 'DBR::Common';
use DBR::Misc::Dummy;
use Carp;
use Scalar::Util 'weaken';
use constant ({
f_next => 0,
f_state => 1,
f_rowcache => 2,
f_query => 3,
f_count => 4,
f_splitval => 5,
stCLEAN => 1,
stACTIVE => 2,
lib/DBR/ResultSet.pm view on Meta::CPAN
$self->[f_state] = stACTIVE;
if( $self->[f_query]->instance->getconn->can_trust_execute_rowcount ){ # HERE - yuck... assumes this is same connection as the sth
$self->[f_count] = $rv + 0;
$self->[f_query]->_logDebug3('ROWS: ' . ($rv + 0));
}
# IMPORTANT NOTE: circular reference hazard
weaken ($self); # Weaken the refcount
my $endsub = sub {
defined($self) or return DUMMY; # technically this could be out of scope because it's a weak ref
$self->[f_count] ||= $sth->rows || 0;
$self->[f_next] = FIRST;
$self->[f_state] = stCLEAN; # If we get here, then we hit the end, and no ->finish is required
return DUMMY; # evaluates to false
};
my $buddy;
my $rows = [];
my $commonref;
my $getchunk = sub {
$rows = $sth->fetchall_arrayref(undef,1000) || return undef; # if cache is empty, fetch more
$commonref = [ @$rows ];
map {weaken $_} @$commonref;
$buddy = [ $commonref, $record ]; # buddy ref must contain the record object just to keep it in scope.
return shift @$rows;
};
# use a closure to reduce hash lookups
# It's very important that this closure is fast.
# This one routine has more of an effect on speed than anything else in the rest of the code
$self->[f_next] = sub {
bless(
( run in 0.775 second using v1.01-cache-2.11-cpan-65fba6d93b7 )