Lim/Util/DBI.pm

filter: Statementstmt 10.7% 30 / 279 Branchbran 0.0% 0 / 120 Conditioncond 0.0% 0 / 29 MC/DCmcdc 0.0% 0 / 19 Subroutinesub 31.0% 9 / 29 Podpod 100% 16 / 16 totaltotal 11.1% 55 / 492 CC 72 SCAR 56.3
CC
72
Cov
7%
new
812.0
__ANON__
240.0
request
110.0
CRAP 279.5
« Lim/RPC/Protocol/HTTP.pm ↑ Summary Lim/Util.pm »
1 package Lim::Util::DBI;
2  
3 1 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Log::Log4perl ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use DBI ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use JSON::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use AnyEvent ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use AnyEvent::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use Lim ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 =encoding utf8
17  
18 =head1 NAME
19  
20 Lim::Util::DBI - Create a DBH that is executed in a forked process
21  
22 =head1 VERSION
23  
24 See L<Lim> for version.
25  
26 =cut
27  
28 1 our $VERSION = $Lim::VERSION;
29 1 our %METHOD = (
30 connect => 1,
31 disconnect => 1,
32 execute => 1,
33 begin_work => 1,
34 commit => 1,
35 rollback => 1
36 );
37  
38 =head1 SYNOPSIS
39  
40 =over 4
41  
42 use Lim::Util::DBI;
43  
44 =back
45  
46 =head1 METHODS
47  
48 =over 4
49  
50 =item new
51  
52 =cut
53  
54 0 ▶sub new {
Subroutine new: not called CC=28 SCAR=67.0
Pod documented
55 0 my $this = shift;
56 0 ▶ my $class = ref($this) || $this;
Condition0%0/3
ref $this || $this
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table0%0/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
57 0 my $dbi = shift;
58 0 my $user = shift;
59 0 my $password = shift;
60 0 my %args = ( @_ );
61 0 my $self = {
62 logger => Log::Log4perl->get_logger($class),
63 json => JSON::XS->new->utf8->convert_blessed,
64 busy => 0
65 };
66 0 bless $self, $class;
67 0 weaken($self->{logger});
68 0 my $real_self = $self;
69 0 weaken($self);
70  
71 0 ▶ unless (defined $dbi) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dbi) 0 0 0
72 0 confess __PACKAGE__, ': Missing dbi connection string';
73 }
74 0 ▶ unless (defined $args{on_connect} and ref($args{on_connect}) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"on_connect"} and ref $args{"on_connect"} eq "CODE") 0 0 0
Condition0%0/3
defined $args{"on_connect"} and ref $args{"on_connect"} eq "CODE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $args{"on_connect"} and ref $args{"on_connect"} eq "CODE"
defined $args{"on_connect"} ref $args{"on_connect"} eq "CODE"
Truth table0%0/3
A and B
A= defined $args{"on_connect"}B= ref $args{"on_connect"} eq "CODE"
ABresult
0X0
100
111
75 0 confess __PACKAGE__, ': Missing on_connect or it is not CODE';
76 }
77  
78 0 my $on_connect = delete $args{on_connect};
79  
80 0 ▶ if (defined $args{on_error}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"on_error"}) 0 0 0
81 0 ▶ unless (ref($args{on_error}) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $args{"on_error"} eq "CODE") 0 0 0
82 0 confess __PACKAGE__, ': on_error is not CODE';
83 }
84 0 $self->{on_error} = delete $args{on_error};
85 }
86  
87 0 my ($child, $parent) = AnyEvent::Util::portable_socketpair;
88 0 ▶ unless (defined $child and defined $parent) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $child and defined $parent) 0 0 0
Condition0%0/3
defined $child and defined $parent
!ll&&!rl&&r
000
MC/DC0%0/2
defined $child and defined $parent
defined $child defined $parent
Truth table0%0/3
A and B
A= defined $childB= defined $parent
ABresult
0X0
100
111
89 0 confess __PACKAGE__, ': Unable to create client/server socket pairs: ', $!;
90 }
91  
92 0 AnyEvent::Util::fh_nonblocking $child, 1;
93 0 $self->{child} = $child;
94  
95 0 my $pid = fork;
96  
97 0 ▶ if ($pid) {
Branch: 2 branches
BranchTrueFalseTotal
if ($pid) { } 0 0 0
elsif (defined $pid) { } 0 0 0
98 #
99 # Parent process
100 #
101  
102 0 close $parent;
103  
104 0 $self->{child_pid} = $pid;
105 $self->{child_watcher} = AnyEvent->io(
106 fh => $child,
107 poll => 'r',
108 0 ▶ cb => sub {
Subroutine __ANON__: not called CC=15 SCAR=54.8
109 0 ▶ unless (defined $self and exists $self->{child}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self and exists $self->{"child"}) 0 0 0
Condition0%0/3
defined $self and exists $self->{"child"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self and exists $self->{"child"}
defined $self exists $self->{"child"}
Truth table0%0/3
A and B
A= defined $selfB= exists $self->{"child"}
ABresult
0X0
100
111
110 0 return;
111 }
112  
113 0 my $response;
114 0 my $len = sysread $self->{child}, my $buf, 64*1024;
115 0 ▶ if ($len > 0) {
Branch: 3 branches
BranchTrueFalseTotal
if ($len > 0) { } 0 0 0
elsif (defined $len) { } 0 0 0
elsif ($! != 11) { } 0 0 0
116 0 undef $@;
117  
118 0 eval {
119 0 $response = $self->{json}->incr_parse($buf);
120 };
121 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 0 0
122 0 ▶ Lim::DEBUG and $self->{logger}->debug('Response JSON parse failed: ', $@);
Branch: 1 branch
BranchTrueFalseTotal
Lim::DEBUG() and $self->{"logger"}->debug("Response JSON parse failed: ", $@) 0 0 0
123 0 $response = [];
124 }
125 else {
126 0 my $errstr = shift @$response;
127 0 ▶ if ($errstr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($errstr) 0 0 0
128 0 $@ = $errstr;
129 }
130 }
131 }
132 elsif (defined $len) {
133 0 $@ = 'Unexpected EOF';
134 0 ▶ Lim::DEBUG and $self->{logger}->debug($@);
Branch: 1 branch
BranchTrueFalseTotal
Lim::DEBUG() and $self->{"logger"}->debug($@) 0 0 0
135  
136 0 shutdown($self->{child}, 2);
137 0 close(delete $self->{child});
138 0 $response = [];
139 }
140 elsif ($! != Errno::EAGAIN) {
141 0 $@ = 'Unable to read from child: '.$!;
142 0 ▶ Lim::DEBUG and $self->{logger}->debug($@);
Branch: 1 branch
BranchTrueFalseTotal
Lim::DEBUG() and $self->{"logger"}->debug($@) 0 0 0
143  
144 0 shutdown($self->{child}, 2);
145 0 close(delete $self->{child});
146 0 $response = [];
147 }
148  
149 0 ▶ if (defined $response and exists $self->{cb}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $response and exists $self->{"cb"}) 0 0 0
Condition0%0/3
defined $response and exists $self->{"cb"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $response and exists $self->{"cb"}
defined $response exists $self->{"cb"}
Truth table0%0/3
A and B
A= defined $responseB= exists $self->{"cb"}
ABresult
0X0
100
111
150 0 ▶ unless (ref($response) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $response eq "ARRAY") 0 0 0
151 0 $@ = 'Invalid response';
152 0 ▶ Lim::DEBUG and $self->{logger}->debug($@);
Branch: 1 branch
BranchTrueFalseTotal
Lim::DEBUG() and $self->{"logger"}->debug($@) 0 0 0
153 0 $response = [];
154 }
155  
156 0 my $cb = delete $self->{cb};
157 0 $self->{busy} = 0;
158 0 $cb->($self, @$response);
159 }
160 0 });
161 }
162 elsif (defined $pid) {
163 #
164 # Child process
165 #
166  
167 0 $SIG{HUP} => 'IGNORE';
168 0 $SIG{INT} => 'IGNORE';
169 0 $SIG{TERM} => 'IGNORE';
170 0 $SIG{PIPE} => 'IGNORE';
171 0 $SIG{QUIT} => 'IGNORE';
172 0 $SIG{ALRM} => 'IGNORE';
173  
174 0 Log::Log4perl->init( \q(
175 log4perl.threshold = OFF
176 log4perl.logger = DEBUG, Screen
177 log4perl.appender.Screen = Log::Log4perl::Appender::Screen
178 log4perl.appender.Screen.stderr = 0
179 log4perl.appender.Screen.layout = Log::Log4perl::Layout::PatternLayout
180 log4perl.appender.Screen.layout.ConversionPattern = %d %F [%L] %p: %m%n
181 ) );
182  
183 0 ▶ if (exists $self->{close_fds} and $self->{close_fds}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"close_fds"} and $self->{"close_fds"}) 0 0 0
Condition0%0/3
exists $self->{"close_fds"} and $self->{"close_fds"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"close_fds"} and $self->{"close_fds"}
exists $self->{"close_fds"} $self->{"close_fds"}
Truth table0%0/3
A and B
A= exists $self->{"close_fds"}B= $self->{"close_fds"}
ABresult
0X0
100
111
184 0 my $parent_fno = fileno $parent;
185  
186 0 ▶ foreach ($^F+1 .. (POSIX::sysconf (&POSIX::_SC_OPEN_MAX) || 1024)) {
Condition0%0/2
POSIX::sysconf(&POSIX::_SC_OPEN_MAX) || 1024
l!l
00
MC/DC0%0/1
POSIX::sysconf(&POSIX::_SC_OPEN_MAX) || 1024
POSIX::sysconf(&POSIX::_SC_OPEN_MAX)
Truth table0%0/2
A
A= POSIX::sysconf(&POSIX::_SC_OPEN_MAX)
Aresult
11
00
187 0 ▶ unless ($_ == $parent_fno) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_ == $parent_fno) 0 0 0
188 0 POSIX::close($_);
189 }
190 }
191 }
192  
193 0 while () {
194 0 my $request;
195 0 my $len = sysread $parent, my $buf, 64*1024;
196 0 ▶ if ($len > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($len > 0) { } 0 0 0
elsif (defined $len) { } 0 0 0
197 0 undef $@;
198  
199 0 eval {
200 0 $request = $self->{json}->incr_parse($buf);
201 };
202 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
203 0 last;
204 }
205 }
206 elsif (defined $len) {
207 0 last;
208 }
209 else {
210 0 last;
211 }
212  
213 0 ▶ if (defined $request) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $request) 0 0 0
214 0 ▶ unless (ref($request) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $request eq "ARRAY") 0 0 0
215 0 last;
216 }
217  
218 0 my $response = $self->process(@$request);
219  
220 0 undef $@;
221 0 eval {
222 0 $response = $self->{json}->encode($response);
223 };
224 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
225 0 my $errstr = $@;
226 0 undef $@;
227 0 eval {
228 0 $response = $self->{json}->encode([$errstr]);
229 };
230 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
231 0 last;
232 }
233 }
234  
235 0 my $wrote = 0;
236 0 my $res_len = length $response;
237 0 while () {
238 0 $len = syswrite $parent, $response, 64*1024;
239 0 ▶ unless (defined $len and $len > 0) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $len and $len > 0) 0 0 0
Condition0%0/3
defined $len and $len > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $len and $len > 0
defined $len $len > 0
Truth table0%0/3
A and B
A= defined $lenB= $len > 0
ABresult
0X0
100
111
240 0 last;
241 }
242  
243 0 $wrote += $len;
244  
245 0 ▶ if ($wrote >= $res_len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wrote >= $res_len) 0 0 0
246 0 last;
247 }
248  
249 0 $response = substr $response, $len;
250 }
251 0 ▶ if ($wrote != $res_len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wrote != $res_len) 0 0 0
252 0 last;
253 }
254 }
255 }
256 0 shutdown($parent, 2);
257 0 close($parent);
258 0 exit(0);
259 }
260 else {
261 0 confess __PACKAGE__, ': Unable to fork: ', $!;
262 }
263  
264 0 $self->connect($on_connect, $dbi, $user, $password, %args);
265  
266 0 ▶ Lim::OBJ_DEBUG and $self->{logger}->debug('new ', __PACKAGE__, ' ', $self);
Branch: 1 branch
BranchTrueFalseTotal
Lim::OBJ_DEBUG() and $self->{"logger"}->debug("new ", __PACKAGE__, " ", $self) 0 0 0
267 0 $self;
268 }
269  
270 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=4 SCAR=30.0
271 0 my ($self) = @_;
272 0 ▶ Lim::OBJ_DEBUG and $self->{logger}->debug('destroy ', __PACKAGE__, ' ', $self);
Branch: 1 branch
BranchTrueFalseTotal
Lim::OBJ_DEBUG() and $self->{"logger"}->debug("destroy ", __PACKAGE__, " ", $self) 0 0 0
273  
274 0 ▶ if (exists $self->{child_pid}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"child_pid"}) 0 0 0
275 0 my $child_watcher; $child_watcher = AnyEvent->child(
276 pid => $self->{child_pid},
277 0 ▶ cb => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
278 0 undef $child_watcher;
279 0 });
280 }
281  
282 0 ▶ if (exists $self->{child}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"child"}) 0 0 0
283 0 shutdown($self->{child}, 2);
284 0 close($self->{child});
285 }
286 }
287  
288 =item process
289  
290 =cut
291  
292 0 ▶sub process {
Subroutine process: not called CC=3 SCAR=24.8
Pod documented
293 0 my $self = shift;
294 0 my $method = shift;
295 0 my $response;
296  
297 0 ▶ unless (exists $METHOD{$method}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Lim::Util::DBI::METHOD{$method}) 0 0 0
298 0 return ['Method '.$method.' is not allowed'];
299 }
300  
301 0 $method = 'child_'.$method;
302 0 eval {
303 0 $response = $self->$method(@_);
304 };
305 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
306 0 return [$@];
307 }
308  
309 0 return $response;
310 }
311  
312 =item request
313  
314 =cut
315  
316 0 ▶sub request {
Subroutine request: not called CC=10 SCAR=47.0
Pod documented
317 0 my $self = shift;
318 0 my $cb = shift;
319 0 my ($method) = @_;
320 0 my $request;
321 0 weaken($self);
322  
323 0 undef $@;
324  
325 0 ▶ unless (ref($cb) eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $cb eq "CODE") 0 0 0
326 0 confess __PACKAGE__, 'cb is not CODE';
327 }
328  
329 0 ▶ unless (exists $METHOD{$method}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Lim::Util::DBI::METHOD{$method}) 0 0 0
330 0 $@ = 'Method '.$method.' is not allowed';
331 0 $cb->();
332 0 return;
333 }
334  
335 0 ▶ unless (exists $self->{child}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"child"}) 0 0 0
336 0 $@ = 'No connection to the DBI process';
337 0 $cb->();
338 0 return;
339 }
340  
341 0 ▶ if ($self->{busy}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"busy"}) 0 0 0
342 0 $@ = 'DBH is busy, multiple command execution is not allowed';
343 0 $cb->();
344 0 return;
345 }
346  
347 0 eval {
348 0 $request = $self->{json}->encode(\@_);
349 };
350 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
351 0 $cb->();
352 0 return;
353 }
354  
355 0 $self->{busy} = 1;
356 0 $self->{cb} = $cb;
357  
358 0 ▶ Lim::DEBUG and $self->{logger}->debug('Sending DBI request ', $method);
Branch: 1 branch
BranchTrueFalseTotal
Lim::DEBUG() and $self->{"logger"}->debug("Sending DBI request ", $method) 0 0 0
359  
360 0 my $len = syswrite $self->{child}, $request;
361 0 ▶ unless (defined $len and $len > 0) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $len and $len > 0) 0 0 0
Condition0%0/3
defined $len and $len > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $len and $len > 0
defined $len $len > 0
Truth table0%0/3
A and B
A= defined $lenB= $len > 0
ABresult
0X0
100
111
362 0 $@ = 'Connection broken';
363 0 $self->kill;
364 0 $cb->();
365 0 return;
366 }
367  
368 0 ▶ unless ($len >= length $request) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($len >= length $request) 0 0 0
369 0 $request = substr $request, $len;
370  
371 $self->{request_watcher} = AnyEvent->io(
372 fh => $request,
373 poll => 'w',
374 0 ▶ cb => sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
375 0 ▶ unless (defined $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self) 0 0 0
376 0 return;
377 }
378  
379 0 $len = syswrite $self->{child}, $request;
380 0 ▶ unless (defined $len and $len > 0) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $len and $len > 0) 0 0 0
Condition0%0/3
defined $len and $len > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $len and $len > 0
defined $len $len > 0
Truth table0%0/3
A and B
A= defined $lenB= $len > 0
ABresult
0X0
100
111
381 0 $@ = 'Connection broken';
382 0 my $cb = $self->{cb};
383 0 $self->kill;
384 0 $cb->();
385 0 return;
386 }
387  
388 0 ▶ unless ($len >= length $request) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($len >= length $request) 0 0 0
389 0 $request = substr $request, $len;
390 0 return;
391 }
392  
393 0 delete $self->{request_watcher};
394 0 });
395 }
396  
397 0 return 1;
398 }
399  
400 =item kill
401  
402 =cut
403  
404 0 ▶sub kill {
Subroutine kill: not called CC=2 SCAR=17.9
Pod documented
405 0 my ($self) = @_;
406  
407 0 ▶ if (exists $self->{child}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"child"}) 0 0 0
408 0 shutdown($self->{child}, 2);
409 0 close(delete $self->{child});
410 }
411  
412 0 delete $self->{child_watcher};
413 0 delete $self->{request_watcher};
414 0 $self->{busy} = 0;
415 0 delete $self->{cb};
416 }
417  
418 =item child_connect
419  
420 =cut
421  
422 0 ▶sub child_connect {
Subroutine child_connect: not called CC=2 SCAR=17.9
Pod documented
423 0 my ($self, $dbi, $user, $pass, $attr) = @_;
424  
425 0 ▶ unless (($self->{dbh} = DBI->connect($dbi, $user, $pass, $attr))) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"dbh"} = "DBI"->connect($dbi, $user, $pass, $attr)) 0 0 0
426 0 return [$DBI::errstr];
427 }
428  
429 0 [0, 1];
430 }
431  
432 =item child_disconnect
433  
434 =cut
435  
436 0 ▶sub child_disconnect {
Subroutine child_disconnect: not called CC=2 SCAR=17.9
Pod documented
437 0 my ($self) = @_;
438  
439 0 ▶ unless (defined $self->{dbh}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"dbh"}) 0 0 0
440 0 return ['No connect to the database exists'];
441 }
442  
443 0 $self->{dbh}->disconnect;
444 0 delete $self->{dbh};
445  
446 0 [0, 1];
447 }
448  
449 =item child_execute
450  
451 =cut
452  
453 0 ▶sub child_execute {
Subroutine child_execute: not called CC=4 SCAR=30.0
Pod documented
454 0 my ($self, $statement, @args) = @_;
455 0 my ($sth, $rv, $rows);
456  
457 0 ▶ unless (defined $self->{dbh}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"dbh"}) 0 0 0
458 0 return ['No connect to the database exists'];
459 }
460  
461 0 ▶ unless (($sth = $self->{dbh}->prepare_cached($statement, undef, 1))) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth = $self->{"dbh"}->prepare_cached($statement, undef, 1)) 0 0 0
462 0 return [$DBI::errstr];
463 }
464  
465 0 ▶ unless (($rv = $sth->execute(@args))) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rv = $sth->execute(@args)) 0 0 0
466 0 return [$sth->errstr];
467 }
468  
469 0 $rows = $sth->fetchall_arrayref;
470 0 $sth->finish;
471  
472 0 [0, $rows, $rv];
473 }
474  
475 =item child_begin_work
476  
477 =cut
478  
479 0 ▶sub child_begin_work {
Subroutine child_begin_work: not called CC=3 SCAR=24.8
Pod documented
480 0 my ($self) = @_;
481  
482 0 ▶ unless (defined $self->{dbh}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"dbh"}) 0 0 0
483 0 return ['No connect to the database exists'];
484 }
485  
486 0 ▶ unless ($self->{dbh}->begin_work) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"dbh"}->begin_work) 0 0 0
487 0 return [$DBI::errstr];
488 }
489  
490 0 [0, 1];
491 }
492  
493 =item child_commit
494  
495 =cut
496  
497 0 ▶sub child_commit {
Subroutine child_commit: not called CC=3 SCAR=24.8
Pod documented
498 0 my ($self) = @_;
499  
500 0 ▶ unless (defined $self->{dbh}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"dbh"}) 0 0 0
501 0 return ['No connect to the database exists'];
502 }
503  
504 0 ▶ unless ($self->{dbh}->commit) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"dbh"}->commit) 0 0 0
505 0 return [$DBI::errstr];
506 }
507  
508 0 [0, 1];
509 }
510  
511 =item child_rollback
512  
513 =cut
514  
515 0 ▶sub child_rollback {
Subroutine child_rollback: not called CC=3 SCAR=24.8
Pod documented
516 0 my ($self) = @_;
517  
518 0 ▶ unless (defined $self->{dbh}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"dbh"}) 0 0 0
519 0 return ['No connect to the database exists'];
520 }
521  
522 0 ▶ unless ($self->{dbh}->rollback) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"dbh"}->rollback) 0 0 0
523 0 return [$DBI::errstr];
524 }
525  
526 0 [0, 1];
527 }
528  
529 =item connect
530  
531 =cut
532  
533 0 ▶sub connect {
Subroutine connect: not called CC=1 SCAR=6.9
Pod documented
534 0 my ($self, $cb, $dbi, $user, $pass, %attr) = @_;
535  
536 0 $self->request($cb, 'connect', $dbi, $user, $pass, \%attr);
537 }
538  
539 =item disconnect
540  
541 =cut
542  
543 0 ▶sub disconnect {
Subroutine disconnect: not called CC=1 SCAR=6.9
Pod documented
544 0 my ($self, $cb) = @_;
545  
546 0 $self->request($cb, 'disconnect');
547 }
548  
549 =item execute
550  
551 =cut
552  
553 0 ▶sub execute {
Subroutine execute: not called CC=1 SCAR=6.9
Pod documented
554 0 my $cb = pop(@_);
555 0 my ($self, $statement, @args) = @_;
556  
557 0 $self->request($cb, 'execute', $statement, @args);
558 }
559  
560 =item begin_work
561  
562 =cut
563  
564 0 ▶sub begin_work {
Subroutine begin_work: not called CC=1 SCAR=6.9
Pod documented
565 0 my ($self, $cb) = @_;
566  
567 0 $self->request($cb, 'begin_work');
568 }
569  
570 =item commit
571  
572 =cut
573  
574 0 ▶sub commit {
Subroutine commit: not called CC=1 SCAR=6.9
Pod documented
575 0 my ($self, $cb) = @_;
576  
577 0 $self->request($cb, 'commit');
578 }
579  
580 =item rollback
581  
582 =cut
583  
584 0 ▶sub rollback {
Subroutine rollback: not called CC=1 SCAR=6.9
Pod documented
585 0 my ($self, $cb) = @_;
586  
587 0 $self->request($cb, 'rollback');
588 }
589  
590 =back
591  
592 =head1 AUTHOR
593  
594 Jerry Lundström, C<< <lundstrom.jerry at gmail.com> >>
595  
596 =head1 BUGS
597  
598 Please report any bugs or feature requests to L<https://github.com/jelu/lim/issues>.
599  
600 =head1 SUPPORT
601  
602 You can find documentation for this module with the perldoc command.
603  
604 perldoc Lim::Util::DBI
605  
606 You can also look for information at:
607  
608 =over 4
609  
610 =item * Lim issue tracker (report bugs here)
611  
612 L<https://github.com/jelu/lim/issues>
613  
614 =back
615  
616 =head1 ACKNOWLEDGEMENTS
617  
618 =head1 LICENSE AND COPYRIGHT
619  
620 Copyright 2012-2013 Jerry Lundström.
621  
622 This program is free software; you can redistribute it and/or modify it
623 under the terms of either: the GNU General Public License as published
624 by the Free Software Foundation; or the Artistic License.
625  
626 See http://dev.perl.org/licenses/ for more information.
627  
628  
629 =cut
630  
631 1 1; # End of Lim::Util::DBI
« Lim/RPC/Protocol/HTTP.pm ↑ Summary Lim/Util.pm »