Data-ObjectDriver
view release on metacpan or search on metacpan
lib/Data/ObjectDriver/Driver/GearmanDBI.pm view on Meta::CPAN
for my $col (@select) {
$hash->{ $map->{$col} } = $array->[$i++];
}
return $hash;
};
my $nt = $args->{no_triggers};
my @objs = map { $dbi->load_object_from_rec($class, $_, $nt); }
map { $to_hash->($_) }
@$results;
return wantarray
? @objs
: Data::ObjectDriver::Iterator->new( sub { shift @objs } );
}
sub _gearman_search {
my $driver = shift;
my ($sql, $bind) = @_;
my $uniqify = $driver->uniqify_cb || \&_md5sum;
my $func = $driver->func;
my $uniq = $uniqify->($sql, $bind);
my $client = $driver->client;
my %options = ();
$options{on_exception} = $driver->on_exception_cb
if $driver->on_exception_cb;
$options{retry_count} = $driver->retry_count
if $driver->retry_count;
$options{timeout} = $driver->timeout
if $driver->timeout;
my $res = $client->do_task( $func =>
\Storable::nfreeze( {
driver_arg => $driver->driver_arg,
sql => $sql,
bind => $bind,
key => $uniq,
} ),
{
uniq => $uniq, # coalesce all requests for this data
%options,
}
);
return $res ? Storable::thaw($$res) : [];
}
sub _md5sum {
my ($sql, $bind) = @_;
return Digest::MD5::md5_hex(join "", $sql, @$bind);
}
## every single data access methods are delegated to dbi
## except for search
sub lookup { shift->dbi->lookup (@_) }
sub lookup_multi { shift->dbi->lookup_multi (@_) }
sub exists { shift->dbi->exists (@_) }
sub insert { shift->dbi->insert (@_) }
sub replace { shift->dbi->replace (@_) }
sub update { shift->dbi->update (@_) }
sub remove { shift->dbi->remove (@_) }
sub fetch_data { shift->dbi->fetch_data (@_) }
## transactions are passed to dbi
sub add_working_driver { shift->dbi->add_working_driver (@_) }
sub commit { shift->dbi->commit (@_) }
sub rollback { shift->dbi->rollback (@_) }
sub rw_handle { shift->dbi->rw_handle (@_) }
sub r_handle { shift->dbi->r_handle (@_) }
## safety AUTOLOAD for the rest of non-core methods
sub DESTROY { }
sub AUTOLOAD {
my $driver = shift;
(my $meth = our $AUTOLOAD) =~ s/^.*:://;
return $driver->dbi->$meth(@_);
}
1;
( run in 0.466 second using v1.01-cache-2.11-cpan-39bf76dae61 )