| 1 | package DBIx::Loop; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 21 | ▶ | use 5.008003; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 21 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 21 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 21 | ▶ | use Carp (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | 21 | our $VERSION = '0.09'; | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 21 | require XSLoader; | |||||||||||||||||||
| 11 | 21 | XSLoader::load('DBIx::Loop', $VERSION); | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 21 | ▶ | use DBI; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 21 | ▶ | use DBIx::Loop::Future; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | =head1 NAME | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | DBIx::Loop - non-blocking DBI on your event loop | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | =head1 VERSION | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | Version 0.09 | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | =cut | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | # connect() is a thin convenience over DBI->connect + new(): the DBI connect is | ||||||||||||||||||||
| 27 | # irreducibly DBI's Perl API. Everything else - the object, capability probe, | ||||||||||||||||||||
| 28 | # query/do dispatch, disconnect, and DBIx::Loop::Future - is XS/C. | ||||||||||||||||||||
| 29 | 18 | ▶ | sub connect { | ||||||||||||||||||
|
Subroutine
connect: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||
| 30 | 18 | my $class = shift; | |||||||||||||||||||
| 31 | 18 | my ($dsn, $user, $pass, $attr, @opt) = @_; | |||||||||||||||||||
| 32 | 18 | my %opt = @opt; | |||||||||||||||||||
| 33 | $opt{loop} = $class->_auto_loop | ||||||||||||||||||||
| 34 | 18 | ▶ | if ($opt{loop} || '') eq 'auto'; | ||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$opt{'loop'} || ''
MC/DC0%0/1
$opt{'loop'} || ''
$opt{'loop'}
Truth table50%1/2
A
A= $opt{'loop'}
| |||||||||||||||||||||
| 35 | 17 | my $dbh = DBI->connect($dsn, $user, $pass, $attr); | |||||||||||||||||||
| 36 | # keep the connect args so the pool's workers can open their own handles | ||||||||||||||||||||
| 37 | 17 | return $class->new( | |||||||||||||||||||
| 38 | dbh => $dbh, | ||||||||||||||||||||
| 39 | dsn => $dsn, user => $user, pass => $pass, attr => $attr, | ||||||||||||||||||||
| 40 | %opt, | ||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | # The DBI select* family is XS (xs/loop.xs): each is query() plus one fixed | ||||||||||||||||||||
| 45 | # reshape of the result, done as a builtin continuation rather than a Perl | ||||||||||||||||||||
| 46 | # closure, so nothing is compiled per call and no Perl frame runs when the | ||||||||||||||||||||
| 47 | # result lands. | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 2 | ▶ | sub _auto_loop { | ||||||||||||||||||
|
Subroutine
_auto_loop: called CC=4 SCAR=15.5
| |||||||||||||||||||||
| 50 | 2 | my ($class) = @_; | |||||||||||||||||||
| 51 | 2 | ▶ | if ($INC{'Mojo/IOLoop.pm'}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | 0 | require DBIx::Loop::Loop::Mojo; | |||||||||||||||||||
| 53 | 0 | return DBIx::Loop::Loop::Mojo->new; | |||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | 2 | ▶ | if ($INC{'IO/Async/Loop.pm'}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | 1 | require DBIx::Loop::Loop::IOAsync; | |||||||||||||||||||
| 57 | 1 | return DBIx::Loop::Loop::IOAsync->new; | |||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | 1 | ▶ | if ($INC{'AnyEvent.pm'}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | 0 | require DBIx::Loop::Loop::AnyEvent; | |||||||||||||||||||
| 61 | 0 | return DBIx::Loop::Loop::AnyEvent->new; | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | 1 | Carp::croak("DBIx::Loop: loop => 'auto' found no loaded event loop " | |||||||||||||||||||
| 64 | . "(Mojo::IOLoop / IO::Async::Loop / AnyEvent) - load one first or " | ||||||||||||||||||||
| 65 | . "pass loop => \$adapter"); | ||||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 21 | 1; | |||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | __END__ | ||||||||||||||||||||