line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
49
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package LittleORM::Db::Connector; |
4
|
1
|
|
|
1
|
|
5
|
use Moose; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
has 'do_dbh_caching' => ( is => 'ro', isa => 'Bool', default => 1 ); |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has 'connect_code' => ( is => 'ro', isa => 'CodeRef' ); |
9
|
|
|
|
|
|
|
has 'connect_read_code' => ( is => 'ro', isa => 'CodeRef' ); |
10
|
|
|
|
|
|
|
has 'connect_write_code' => ( is => 'ro', isa => 'CodeRef' ); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has '__cached_read_dbh' => ( is => 'rw', isa => 'DBI::db' ); |
13
|
|
|
|
|
|
|
has '__cached_write_dbh' => ( is => 'rw', isa => 'DBI::db' ); |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
3934
|
use Carp::Assert 'assert'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
16
|
1
|
|
|
1
|
|
93
|
use LittleORM::Db (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
273
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub get_dbh |
19
|
|
|
|
|
|
|
{ |
20
|
0
|
|
|
0
|
0
|
|
my ( $self, $for_what ) = @_; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
my $rv = undef; |
23
|
|
|
|
|
|
|
|
24
|
0
|
0
|
|
|
|
|
if( $for_what eq 'read' ) |
|
|
0
|
|
|
|
|
|
25
|
|
|
|
|
|
|
{ |
26
|
0
|
|
|
|
|
|
$rv = $self -> get_read_dbh(); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
} elsif( $for_what eq 'write' ) |
29
|
|
|
|
|
|
|
{ |
30
|
0
|
|
|
|
|
|
$rv = $self -> get_write_dbh(); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
} else |
33
|
|
|
|
|
|
|
{ |
34
|
0
|
|
|
|
|
|
assert( 0, 'for what: ' . $for_what ); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
assert( &LittleORM::Db::dbh_is_ok( $rv ) ); |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
return $rv; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub get_read_dbh |
43
|
|
|
|
|
|
|
{ |
44
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $rv = undef; |
47
|
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
if( $self -> do_dbh_caching() ) |
49
|
|
|
|
|
|
|
{ |
50
|
0
|
0
|
|
|
|
|
if( my $t = &LittleORM::Db::dbh_is_ok( $self -> __cached_read_dbh() ) ) |
51
|
|
|
|
|
|
|
{ |
52
|
0
|
|
|
|
|
|
$rv = $t; |
53
|
|
|
|
|
|
|
} else |
54
|
|
|
|
|
|
|
{ |
55
|
0
|
|
|
|
|
|
$rv = $self -> __do_actually_connect_read_dbh(); |
56
|
0
|
|
|
|
|
|
$self -> __cached_read_dbh( $rv ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
} else |
60
|
|
|
|
|
|
|
{ |
61
|
0
|
|
|
|
|
|
$rv = $self -> __do_actually_connect_read_dbh(); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
return $rv; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub get_write_dbh |
68
|
|
|
|
|
|
|
{ |
69
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $rv = undef; |
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
if( $self -> do_dbh_caching() ) |
74
|
|
|
|
|
|
|
{ |
75
|
0
|
0
|
|
|
|
|
if( my $t = &LittleORM::Db::dbh_is_ok( $self -> __cached_write_dbh() ) ) |
76
|
|
|
|
|
|
|
{ |
77
|
0
|
|
|
|
|
|
$rv = $t; |
78
|
|
|
|
|
|
|
} else |
79
|
|
|
|
|
|
|
{ |
80
|
0
|
|
|
|
|
|
$rv = $self -> __do_actually_connect_write_dbh(); |
81
|
0
|
|
|
|
|
|
$self -> __cached_write_dbh( $rv ); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
} else |
85
|
|
|
|
|
|
|
{ |
86
|
0
|
|
|
|
|
|
$rv = $self -> __do_actually_connect_write_dbh(); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
return $rv; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub __do_actually_connect_read_dbh |
93
|
|
|
|
|
|
|
{ |
94
|
0
|
|
|
0
|
|
|
my $self = shift; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
0
|
|
|
|
my $code = ( $self -> connect_read_code() |
97
|
|
|
|
|
|
|
or |
98
|
|
|
|
|
|
|
$self -> connect_code() ); |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
assert( ref( $code ) eq 'CODE' ); |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
my $rv = $code -> (); |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
return $rv; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub __do_actually_connect_write_dbh |
108
|
|
|
|
|
|
|
{ |
109
|
0
|
|
|
0
|
|
|
my $self = shift; |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
0
|
|
|
|
my $code = ( $self -> connect_write_code() |
112
|
|
|
|
|
|
|
or |
113
|
|
|
|
|
|
|
$self -> connect_code() ); |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
assert( ref( $code ) eq 'CODE' ); |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
my $rv = $code -> (); |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
return $rv; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
"yz"; |