blib/lib/DBIx/MysqlCoroAnyEvent.pm untested

filter: Statementstmt 0.0% 0 / 54 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 83 CC 3 SCAR 10.8
CC
3
Cov
0%
prepare
6.0
do
6.0
BEGIN
2.0
CRAP 2.9
1 {
2  
3 package DBIx::MysqlCoroAnyEvent;
4  
5 our $VERSION = "0.02";
6 use base 'DBI';
7  
8 =head1 NAME
9
10 DBIx::MysqlCoroAnyEvent - DBD::mysql + Coro + AnyEvent
11
12 =head1 SYNOPSIS
13
14 use DBI;
15 $dbh = DBI->connect("dbi:mysql:dbname=$dbname", $username, $auth, { RootClass =>"DBIx::MysqlCoroAnyEvent", %rest_attr});
16  
17 =cut
18  
19 }
20 {
21  
22 package DBIx::MysqlCoroAnyEvent::db;
23 use DBD::mysql;
24 use DBI;
25 use base 'DBI::db';
26 use strict;
27 use warnings;
28  
29 sub prepare {
30 my ($dbh, $statement, @attribs) = @_;
31 return undef if !defined $statement;
32 $attribs[0]{async} = 1;
33 $dbh->SUPER::prepare($statement, @attribs);
34 }
35  
36 sub do {
37 my ($dbh, $statement, $attr, @params) = @_;
38 my $sth = prepare($dbh, $statement, $attr) or return;
39 $sth->execute(@params) or return;
40 my $rows = $sth->rows;
41 ($rows == 0) ? "0E0" : $rows;
42 }
43  
44 BEGIN {
45 no warnings 'once';
46 *selectrow_array = \&DBD::_::db::selectrow_array;
47 *selectrow_arrayref = \&DBD::_::db::selectrow_arrayref;
48 *selectall_arrayref = \&DBD::_::db::selectall_arrayref;
49 }
50 }
51  
52 {
53  
54 package DBIx::MysqlCoroAnyEvent::st;
55 use Coro;
56 use AnyEvent;
57 use Coro::AnyEvent;
58 use base 'DBI::st';
59  
60 sub execute {
61 my ($sth, @vars) = @_;
62 my $res = $sth->SUPER::execute(@vars);
63 my $dbh = $sth->{Database};
64 Coro::AnyEvent::readable $dbh->mysql_fd while !$sth->mysql_async_ready;
65 $sth->mysql_async_result;
66 }
67 }
68  
69 1;