AnyEvent-DBI
view release on metacpan or search on metacpan
my $fork = delete $arg{fork_template};
my %dbi_args = %arg;
delete @dbi_args{qw(on_connect on_error timeout fork_template exec_server)};
my $self = bless \%arg, $class;
$self->{fh} = $client;
my $rbuf;
my @caller = (caller)[1,2]; # the "default" caller
$fork = $fork ? $fork->fork : AnyEvent::Fork->new
or croak "fork: $!";
$fork->require ("AnyEvent::DBI::Slave");
$fork->send_arg ($VERSION);
$fork->send_fh ($server);
# we don't rely on the callback, because we use our own
# socketpair, for better or worse.
substr $self->{wbuf}, 0, $len, "";
};
}
$self->_req (
sub {
return unless $self;
$self->{child_pid} = $_[1];
},
(caller)[1,2],
"req_pid"
);
$self->_req (
sub {
return unless $self;
&{ $self->{on_connect} } if $self->{on_connect};
},
(caller)[1,2],
req_open => $dbi, $user, $pass, %dbi_args
);
$self
}
sub _server_pid {
shift->{child_pid}
}
die "EVAL failed: $errstr"
if $errcode;
# otherwise, we can ignore $rc and $errcode for this particular func
=cut
for my $cmd_name (qw(attr exec stattr begin_work commit rollback func)) {
eval 'sub ' . $cmd_name . '{
my $cb = pop;
splice @_, 1, 0, $cb, (caller)[1,2], "req_' . $cmd_name . '";
&_req
}';
}
=back
=head1 SEE ALSO
L<AnyEvent>, L<DBI>, L<Coro::Mysql>.
( run in 0.942 second using v1.01-cache-2.11-cpan-1e74a51a04c )