Permalink
Browse files

added EXPERIMETNAL aysnc_conf attribute

  • Loading branch information...
1 parent b0f4985 commit 64c5849f9ed2338cb906a1c892e8ce1cb544d355 @yuki-kimoto committed Feb 10, 2012
Showing with 31 additions and 6 deletions.
  1. +3 −1 Changes
  2. +20 −2 lib/DBIx/Custom.pm
  3. +8 −3 t/mysql-async-opt.t
View
@@ -1,4 +1,6 @@
-0.2108
+0.2110
+ - added EXPERIMETNAL aysnc_conf attribute
+0.2109
- select method can be called even if table name is not specified
0.2108
- added async database access support using AnyEvent
View
@@ -1,7 +1,7 @@
package DBIx::Custom;
use Object::Simple -base;
-our $VERSION = '0.2109';
+our $VERSION = '0.2110';
use 5.008001;
use Carp 'croak';
@@ -22,6 +22,7 @@ use Scalar::Util qw/weaken/;
has [qw/connector dsn password quote user exclude_table user_table_info
user_column_info safety_character/],
+ async_conf => sub { {} },
cache => 0,
cache_method => sub {
sub {
@@ -346,6 +347,7 @@ sub execute {
my %opt = @_;
# Async query
+ $opt{prepare_attr} = $self->async_conf->{prepare_attr} if $opt{async};
if ($opt{async} && !$self->{_new_connection}) {
my $dsn = $self->dsn;
croak qq/Data source must be specified when "async" option is used/
@@ -612,7 +614,7 @@ sub execute {
my $watcher;
weaken $self;
$watcher = AnyEvent->io(
- fh => $self->{dbh}->mysql_fd,
+ fh => $self->async_conf->{fh}->($self),
poll => 'r',
cb => sub {
$cb->($self, $result);
@@ -2183,6 +2185,22 @@ L<DBIx::Custom::Order>
=head1 ATTRIBUTES
+=head2 C<async_conf> EXPERIMENTAL
+
+ my $async_conf = $dbi->async_conf;
+ $dbi = $dbi->async_conf($conf);
+
+Setting when C<async> option is used.
+
+ # MySQL
+ $dbi->async_conf({
+ prepare_attr => {async => 1},
+ fh => sub { shift->dbh->mysql_fd }
+ })
+
+C<prepare_attr> is DBI's C<prepare> method second argument,
+C<fh> is callback that return file handle to watch.
+
=head2 C<connector>
my $connector = $dbi->connector;
View
@@ -67,8 +67,13 @@ my $timer = AnyEvent->timer(
my $count = 0;
+$dbi->async_conf({
+ prepare_attr => {async => 1},
+ fh => sub { shift->dbh->mysql_fd }
+});
+
$dbi->execute('SELECT SLEEP(1), 3', undef,
- prepare_attr => {async => 1}, select => 1,
+ select => 1,
async => sub {
my ($dbi, $result) = @_;
my $row = $result->fetch_one;
@@ -77,12 +82,12 @@ $dbi->execute('SELECT SLEEP(1), 3', undef,
}
);
-$dbi->select('key1', table => 'table1', prepare_attr => {async => 1},
+$dbi->select('key1', table => 'table1',
async => sub {
my ($dbi, $result) = @_;
my $row = $result->fetch_one;
is($row->[0], 1, 'after1');
- $dbi->select('key1', table => 'table1', prepare_attr => {async => 1},
+ $dbi->select('key1', table => 'table1',
async => sub {
my ($dbi, $result) = @_;
my $row = $result->fetch_one;

0 comments on commit 64c5849

Please sign in to comment.