MoCo/DataBase.pm

filter: Statementstmt 84.4% 168 / 199 Branchbran 56.7% 67 / 118 Conditioncond 61.2% 19 / 31 MC/DCmcdc 42.1% 8 / 19 Subroutinesub 92.3% 24 / 26 Podpod 7.6% 1 / 13 totaltotal 70.6% 287 / 406 CC 71 SCAR 24.3
CC
71
Cov
73%
execute
33.6
primary_keys
17.4
unique_keys
13.0
CRAP 11.3
« MoCo/List.pm ↑ Summary MoCo/Fixture.pm »
1 package DBIx::MoCo::DataBase;
2 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 13 ▶use base qw (Class::Data::Inheritable);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 13 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 13 ▶use SQL::Abstract;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 13 __PACKAGE__->mk_classdata($_) for qw(username password
10 cache_connection last_insert_id);
11 13 __PACKAGE__->cache_connection(1);
12  
13 13 our $DEBUG = 0;
14 13 our $SQL_COUNT = 0;
15  
16 # $Carp::CarpLevel = 2;
17 13 my $sqla = SQL::Abstract->new;
18  
19 23 ▶sub insert {
Subroutine insert: called CC=1 SCAR=0.0
Pod undocumented
20 23 my $class = shift;
21 23 my ($table, $args) = @_;
22 23 my ($sql, @binds) = $sqla->insert($table,$args);
23 23 $class->execute($sql,undef,\@binds);
24 }
25  
26 4 ▶sub delete {
Subroutine delete: called CC=5 SCAR=17.5
Pod undocumented
27 4 my $class = shift;
28 4 my ($table, $where) = @_;
29 4 ▶ $where or croak "where is not specified to delete from $table";
Branch: 1 branch
BranchTrueFalseTotal
$where or croak("where is not specified to delete from $table") 4 0 4
30 4 ▶ (ref $where eq 'HASH' && %$where) or croak "where is not specified to delete from $table";
Branch: 1 branch
BranchTrueFalseTotal
ref $where eq "HASH" and %$where or croak("where is not specified to delete from $table") 4 0 4
Condition33%1/3
ref $where eq "HASH" and %$where
!ll&&!rl&&r
004
MC/DC0%0/2
ref $where eq "HASH" and %$where
ref $where eq "HASH" %$where
Truth table33%1/3
A and B
A= ref $where eq "HASH"B= %$where
ABresult
0X0
100
111
31 4 my ($sql, @binds) = $sqla->delete($table,$where);
32 4 ▶ $sql =~ /WHERE/io or croak "where is not specified to delete from $table";
Branch: 1 branch
BranchTrueFalseTotal
$sql =~ /WHERE/io or croak("where is not specified to delete from $table") 4 0 4
33 4 $class->execute($sql,undef,\@binds);
34 }
35  
36 12 ▶sub update {
Subroutine update: called CC=5 SCAR=17.5
Pod undocumented
37 12 my $class = shift;
38 12 my ($table, $args, $where) = @_;
39 12 ▶ $where or croak "where is not specified to update $table";
Branch: 1 branch
BranchTrueFalseTotal
$where or croak("where is not specified to update $table") 12 0 12
40 12 ▶ (ref $where eq 'HASH' && %$where) or croak "where is not specified to update $table";
Branch: 1 branch
BranchTrueFalseTotal
ref $where eq "HASH" and %$where or croak("where is not specified to update $table") 12 0 12
Condition33%1/3
ref $where eq "HASH" and %$where
!ll&&!rl&&r
0012
MC/DC0%0/2
ref $where eq "HASH" and %$where
ref $where eq "HASH" %$where
Truth table33%1/3
A and B
A= ref $where eq "HASH"B= %$where
ABresult
0X0
100
111
41 12 my ($sql, @binds) = $sqla->update($table,$args,$where);
42 12 ▶ $sql =~ /WHERE/io or croak "where is not specified to update $table";
Branch: 1 branch
BranchTrueFalseTotal
$sql =~ /WHERE/io or croak("where is not specified to update $table") 12 0 12
43 12 $class->execute($sql,undef,\@binds);
44 }
45  
46 35 ▶sub select {
Subroutine select: called CC=3 SCAR=11.2
Pod undocumented
47 35 my $class = shift;
48 35 my ($table, $args, $where, $order, $limit) = @_;
49 35 my ($sql, @binds) = $sqla->select($table,$args,$where,$order);
50 35 ▶ $sql .= $class->_parse_limit($limit) if $limit;
Branch: 1 branch
BranchTrueFalseTotal
if $limit 0 35 35
51 35 my $data;
52 35 ▶ $class->execute($sql,\$data,\@binds) or return;
Branch: 1 branch
BranchTrueFalseTotal
$class->execute($sql, \$data, \@binds) or return 35 0 35
53 35 return $data;
54 }
55  
56 40 ▶sub search {
Subroutine search: called CC=2 SCAR=7.0
Pod undocumented
57 40 my $class = shift;
58 40 my %args = @_;
59 40 my ($sql, @binds) = $class->_search_sql(\%args);
60 40 my $data;
61 40 ▶ $class->execute($sql,\$data,\@binds) or return;
Branch: 1 branch
BranchTrueFalseTotal
$class->execute($sql, \$data, \@binds) or return 40 0 40
62 40 return $data;
63 }
64  
65 40 ▶sub _search_sql {
Subroutine _search_sql: called CC=6 SCAR=18.0
66 40 my $class = shift;
67 40 my $args = shift;
68 40 ▶ my $field = $args->{field} || "*";
Condition100%2/2
$args->{'field'} || '*'
l!l
2317
MC/DC100%1/1
$args->{'field'} || '*'
$args->{'field'}
Truth table100%2/2
A
A= $args->{'field'}
Aresult
11
00
69 40 my $sql = "SELECT $field FROM " . $args->{table};
70 40 ▶ $sql .= " USE INDEX ($args->{use_index})" if $args->{use_index};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"use_index"} 0 40 40
71 40 my ($where,@binds) = $class->_parse_where($args->{where});
72 40 ▶ $sql .= $where if $where;
Branch: 1 branch
BranchTrueFalseTotal
if $where 38 2 40
73 40 ▶ $sql .= " GROUP BY $args->{group}" if $args->{group};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"group"} 0 40 40
74 40 ▶ $sql .= " ORDER BY $args->{order}" if $args->{order};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"order"} 4 36 40
75 40 $sql .= $class->_parse_limit($args);
76 40 return ($sql,@binds);
77 }
78  
79 40 ▶sub _parse_where {
Subroutine _parse_where: called CC=9 SCAR=22.2
80 40 my ($class, $where) = @_;
81 40 my $binds = [];
82 40 ▶ if (ref $where eq 'ARRAY') {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $where eq 'ARRAY') { } 19 21 40
elsif (ref $where eq 'HASH') { } 16 5 21
elsif ($where) { } 3 2 5
83 19 my $sql = shift @$where;
84 19 ▶ if ($sql =~ m!\s*:[A-Za-z_][A-Za-z0-9_]+\s*!o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sql =~ /\s*:[A-Za-z_][A-Za-z0-9_]+\s*/o) { } 1 18 19
85 1 ▶ @$where % 2 and croak "You gave me an odd number of parameters to 'where'!";
Branch: 1 branch
BranchTrueFalseTotal
@$where % 2 and croak("You gave me an odd number of parameters to 'where'!") 0 1 1
86 1 my %named_values = @$where;
87 1 my @values;
88 1 $sql =~ s{:([A-Za-z_][A-Za-z0-9_]*)}{
89 1 ▶ croak "$1 is not exists in hash" if !exists $named_values{$1};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $named_values{$1} 0 1 1
90 1 my $value = $named_values{$1};
91 1 ▶ if (ref $value eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 0 1 1
92 0 push @values, $_ for @$value;
93 0 join ',', map('?', 1..@$value);
94 } else {
95 1 push @values, $value;
96 1 '?'
97 }
98 }ge;
99 1 $binds = \@values;
100 } else {
101 18 $binds = $where;
102 }
103 19 return (' WHERE ' . $sql, @$binds);
104 } elsif (ref $where eq 'HASH') {
105 16 return $sqla->where($where);
106 } elsif ($where) {
107 3 return ' WHERE ' . $where;
108 }
109 2 return $where;
110 }
111  
112 40 ▶sub _parse_limit {
Subroutine _parse_limit: called CC=6 SCAR=18.0
113 40 my ($class, $args) = @_;
114 40 my $sql = '';
115 40 ▶ if ($args->{offset} || $args->{limit}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"offset"} or $args->{"limit"}) 7 33 40
Condition100%3/3
$args->{"offset"} or $args->{"limit"}
l!l&&r!l&&!r
1633
MC/DC100%2/2
$args->{"offset"} or $args->{"limit"}
$args->{"offset"} $args->{"limit"}
Truth table100%3/3
A or B
A= $args->{"offset"}B= $args->{"limit"}
ABresult
1X1
011
000
116 7 $sql .= " LIMIT ";
117 7 ▶ if ($args->{offset} && $args->{offset} =~ m/^\d+$/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"offset"} and $args->{"offset"} =~ /^\d+$/o) 1 6 7
Condition66%2/3
$args->{"offset"} and $args->{"offset"} =~ /^\d+$/o
!ll&&!rl&&r
601
MC/DC50%1/2
$args->{"offset"} and $args->{"offset"} =~ /^\d+$/o
$args->{"offset"} $args->{"offset"} =~ /^\d+$/o
Truth table66%2/3
A and B
A= $args->{"offset"}B= $args->{"offset"} =~ /^\d+$/o
ABresult
0X0
100
111
118 1 $sql .= $args->{offset}.",";
119 }
120 7 ▶ $sql .= $args->{limit} =~ /^\d+$/o ? $args->{limit} : '1';
Branch: 1 branch
BranchTrueFalseTotal
$args->{'limit'} =~ /^\d+$/o ? : 7 0 7
121 }
122 40 return $sql;
123 }
124  
125 20 ▶sub dsn {
Subroutine dsn: called CC=10 SCAR=23.1
Pod documented
126 20 my $class = shift;
127 20 my ($master_dsn, $slave_dsn);
128 20 ▶ if ($_[0] && ref($_[0]) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] and ref $_[0] eq "HASH") 1 19 20
Condition66%2/3
$_[0] and ref $_[0] eq "HASH"
!ll&&!rl&&r
0191
MC/DC50%1/2
$_[0] and ref $_[0] eq "HASH"
$_[0] ref $_[0] eq "HASH"
Truth table66%2/3
A and B
A= $_[0]B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
129 1 @_ = (%{$_[0]});
130 }
131 20 ▶ if ($_[1]) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_[1]) { } 3 17 20
elsif ($_[0]) { } 17 0 17
132 3 my %args = @_;
133 3 ▶ my $master = $args{master} or croak "master dsn is not specified";
Branch: 1 branch
BranchTrueFalseTotal
my $master = $args{"master"} or croak("master dsn is not specified") 3 0 3
134 3 ▶ $master_dsn = ref($master) eq 'ARRAY' ? $master : [$master];
Branch: 1 branch
BranchTrueFalseTotal
ref $master eq 'ARRAY' ? : 1 2 3
135 3 ▶ my $slave = $args{slave} || $master;
Condition66%2/3
$args{'slave'} || $master
l!l&&r!l&&!r
210
MC/DC0%0/2
$args{'slave'} || $master
$args{'slave'} $master
Truth table66%2/3
A || B
A= $args{'slave'}B= $master
ABresult
1X1
011
000
136 3 ▶ $slave_dsn = ref($slave) eq 'ARRAY' ? $slave : [$slave];
Branch: 1 branch
BranchTrueFalseTotal
ref $slave eq 'ARRAY' ? : 3 0 3
137 } elsif ($_[0]) {
138 17 ▶ $slave_dsn = $master_dsn = ref($_[0]) eq 'ARRAY' ? $_[0] : [$_[0]];
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'ARRAY' ? : 1 16 17
139 } else {
140 0 croak "Please specify your dsn.";
141 }
142 # $dsn->{$class} = {
143 # master => $master_dsn,
144 # slave => $slave_dsn,
145 # };
146 20 my $getter = $class . '::get_dsn';
147 {
148 13 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
149 13 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
150 20 ▶ *{$getter} = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
151 416 my $class = shift;
152 416 my $sql = shift;
153 416 my $list = $master_dsn;
154 416 ▶ if ($sql && $sql =~ /^SELECT/io) { $list = $slave_dsn }
Branch: 1 branch
BranchTrueFalseTotal
if ($sql and $sql =~ /^SELECT/io) 87 329 416
Condition100%3/3
$sql and $sql =~ /^SELECT/io
!ll&&!rl&&r
6426587
MC/DC100%2/2
$sql and $sql =~ /^SELECT/io
$sql $sql =~ /^SELECT/io
Truth table100%3/3
A and B
A= $sqlB= $sql =~ /^SELECT/io
ABresult
0X0
100
111
155 416 my $dsn = shift @$list;
156 416 push @$list, $dsn;
157 416 return $dsn;
158 }
159 20 }
160 }
161  
162 0 ▶sub get_dsn { croak "You must set up your dsn first" }
Subroutine get_dsn: not called CC=1 SCAR=6.9
Pod undocumented
163  
164 393 ▶sub dbh {
Subroutine dbh: called CC=2 SCAR=7.0
Pod undocumented
165 393 my $class = shift;
166 393 my $sql = shift;
167 393 ▶ my $connect = $class->cache_connection ? 'connect_cached' : 'connect';
Branch: 1 branch
BranchTrueFalseTotal
$class->cache_connection ? : 393 0 393
168 393 my $dsn = $class->get_dsn($sql);
169 393 my $opt = {RaiseError => 1};
170 393 DBI->$connect($dsn, $class->username, $class->password, $opt);
171 }
172  
173 340 ▶sub execute {
Subroutine execute: called CC=15 SCAR=35.1
Pod undocumented
174 340 my $class = shift;
175 340 my ($sql, $data, $binds) = @_;
176 340 ▶ $sql or return;
Branch: 1 branch
BranchTrueFalseTotal
$sql or return 340 0 340
177 340 ▶ my @bind_values = ref $binds eq 'ARRAY' ? @$binds : ();
Branch: 1 branch
BranchTrueFalseTotal
ref $binds eq 'ARRAY' ? : 285 55 340
178 340 my $dbh = $class->dbh(substr($sql,0,8));
179 340 ▶ my $sth = @bind_values ? $dbh->prepare_cached($sql,undef,1) :
Branch: 1 branch
BranchTrueFalseTotal
@bind_values ? : 280 60 340
180 $dbh->prepare($sql);
181 0 ▶ unless ($sth) { carp $dbh->errstr and return; }
Branch: 2 branches
BranchTrueFalseTotal
unless ($sth) 0 340 340
carp($dbh->errstr) and return 0 0 0
182 340 ▶ if ($DEBUG) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DBIx::MoCo::DataBase::DEBUG) 0 340 340
183 0 ▶ my @binds = map { defined $_ ? "'$_'" : "'NULL'" } @bind_values;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
184 0 carp $sql . '->execute(' . join(',', @binds) . ')';
185 0 $SQL_COUNT++;
186 }
187  
188 0 ▶ my $sql_error = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
189 0 my ($sql, $sth) = @_;
190 0 ▶ defined $data
Branch: 1 branch
BranchTrueFalseTotal
defined $data ? : 0 0 0
191 ? sprintf('SQL Error: "%s" (%s)', $sql, $sth->errstr)
192 : sprintf('SQL Error "%s"', $sql);
193 340 };
194  
195 340 eval {
196 340 ▶ if (defined $data) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data) { } 80 260 340
197 80 ▶ $sth->execute(@bind_values) or carp $sql_error->($sth, $sql) and return;
Branch: 1 branch
BranchTrueFalseTotal
$sth->execute(@bind_values) or carp(&$sql_error($sth, $sql)) and return 80 0 80
Condition20%1/5
$sth->execute(@bind_values) || carp(&$sql_error($sth, $sql)) && (return)
l!l&&r!l&&!r
8000
carp(&$sql_error($sth, $sql)) and return
!ll
00
MC/DC0%0/2
$sth->execute(@bind_values) || carp(&$sql_error($sth, $sql)) && (return)
$sth->execute(@bind_values) carp(&$sql_error($sth, $sql))
Truth table33%1/3
A || B
A= $sth->execute(@bind_values)B= carp(&$sql_error($sth, $sql))
ABresult
1X1
011
000
198 80 $$data = $sth->fetchall_arrayref({});
199 } else {
200 260 ▶ unless ($sth->execute(@bind_values)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sth->execute(@bind_values)) 0 260 260
201 0 $sql_error->($sql, $sth);
202 0 return;
203 }
204 }
205 };
206 340 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 340 340
207 0 confess $sql_error->($sql, $sth);
208 }
209  
210 340 ▶ if ($sql =~ /^insert/io) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sql =~ /^insert/io) 179 161 340
211 $class->last_insert_id($dbh->last_insert_id(undef,undef,undef,undef) ||
212 179 ▶ $dbh->{'mysql_insertid'});
Condition66%2/3
$dbh->last_insert_id(undef, undef, undef, undef) || $dbh->{'mysql_insertid'}
l!l&&r!l&&!r
17801
MC/DC50%1/2
$dbh->last_insert_id(undef, undef, undef, undef) || $dbh->{'mysql_insertid'}
$dbh->last_insert_id(undef, undef, undef, undef) $dbh->{'mysql_insertid'}
Truth table66%2/3
A || B
A= $dbh->last_insert_id(undef, undef, undef, undef)B= $dbh->{'mysql_insertid'}
ABresult
1X1
011
000
213 }
214 340 return !$sth->err;
215 }
216  
217 10 ▶sub vendor {
Subroutine vendor: called CC=1 SCAR=0.0
Pod undocumented
218 10 my $class = shift;
219 10 $class->dbh->get_info(17); # SQL_DBMS_NAME
220 }
221  
222 8 ▶sub primary_keys {
Subroutine primary_keys: called CC=6 SCAR=28.6
Pod undocumented
223 8 my $class = shift;
224 8 ▶ my $table = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $table = shift() or return 8 0 8
225 8 my $dbh = $class->dbh;
226 8 ▶ if ($class->vendor eq 'MySQL') {
Branch: 1 branch
BranchTrueFalseTotal
if ($class->vendor eq 'MySQL') { } 0 8 8
227 0 ▶ my $sth = $dbh->column_info(undef,undef,$table,'%') or
Branch: 1 branch
BranchTrueFalseTotal
my $sth = $dbh->column_info(undef, undef, $table, "%") or croak($dbh->errstr) 0 0 0
228 croak $dbh->errstr;
229 0 ▶ $dbh->err and croak $dbh->errstr;
Branch: 1 branch
BranchTrueFalseTotal
$dbh->err and croak($dbh->errstr) 0 0 0
230 0 ▶ my @cols = @{$sth->fetchall_arrayref({})} or
Branch: 1 branch
BranchTrueFalseTotal
my(@cols) = @{$sth->fetchall_arrayref({});} or croak("couldnt get primary keys") 0 0 0
231 croak "couldnt get primary keys";
232 return [
233 0 map {$_->{COLUMN_NAME}}
234 0 grep {$_->{mysql_is_pri_key}}
235 @cols
236 ];
237 } else {
238 8 return [$dbh->primary_key(undef,undef,$table)];
239 }
240 }
241  
242 2 ▶sub unique_keys {
Subroutine unique_keys: called CC=5 SCAR=25.7
Pod undocumented
243 2 my $class = shift;
244 2 ▶ my $table = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $table = shift() or return 2 0 2
245 2 ▶ if ($class->vendor eq 'MySQL') {
Branch: 1 branch
BranchTrueFalseTotal
if ($class->vendor eq 'MySQL') { } 0 2 2
246 0 my $sql = "SHOW INDEX FROM $table";
247 0 my $data;
248 0 ▶ $class->execute($sql,\$data) or
Branch: 1 branch
BranchTrueFalseTotal
$class->execute($sql, \$data) or croak("couldnt get unique keys") 0 0 0
249 croak "couldnt get unique keys";
250 0 ▶ @$data or croak "couldnt get unique keys";
Branch: 1 branch
BranchTrueFalseTotal
@$data or croak("couldnt get unique keys") 0 0 0
251 return [
252 0 map {$_->{Column_name}}
253 0 grep {!$_->{Non_unique}}
254 @$data
255 ];
256 } else {
257 2 return $class->primary_keys($table);
258 }
259 }
260  
261 13 ▶sub columns {
Subroutine columns: called CC=6 SCAR=21.4
Pod undocumented
262 13 my $class = shift;
263 13 ▶ my $table = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $table = shift() or return 13 0 13
264 13 my $dbh = $class->dbh;
265 13 ▶ if (my $sth = $class->dbh->column_info(undef,undef,$table,'%')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sth = $class->dbh->column_info(undef, undef, $table, '%')) { } 13 0 13
266 13 ▶ croak $dbh->errstr if $dbh->err;
Branch: 1 branch
BranchTrueFalseTotal
if $dbh->err 0 13 13
267 13 ▶ my @cols = @{$sth->fetchall_arrayref({})} or
Branch: 1 branch
BranchTrueFalseTotal
my(@cols) = @{$sth->fetchall_arrayref({});} or croak("couldnt get primary keys") 13 0 13
268 croak "couldnt get primary keys";
269 return [
270 13 map {$_->{COLUMN_NAME}}
271 @cols
272 ];
273 } else {
274 0 ▶ my $d = $class->select($table,'*',undef,'',{limit => 1}) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $d = $class->select($table, "*", undef, "", {"limit", 1}) or return 0 0 0
275 0 return [keys %{$d->[0]}];
276 }
277 }
278  
279 13 1;
280  
281 =head1 NAME
282  
283 DBIx::MoCo::DataBase - Data Base Handler for DBIx::MoCo
284  
285 =head1 SYNOPSIS
286  
287 package MyDataBase;
288 use base qw(DBIx::MoCo::DataBase);
289  
290 __PACKAGE__->dsn('dbi:mysql:myapp');
291 __PACKAGE__->username('test');
292 __PACKAGE__->password('test');
293  
294 1;
295  
296 # In your scripts
297 MyDataBase->execute('select 1');
298  
299 # Configure your replication databases
300 __PACKAGE__->dsn(
301 master => 'dbi:mysql:dbname=test;host=db1',
302 slave => ['dbi:mysql:dbname=test;host=db2','dbi:mysql:dbname=test;host=db3'],
303 );
304  
305 =head1 METHODS
306  
307 =over 4
308  
309 =item cache_connection
310  
311 Controlls cache behavior for dbh connection. (default 1)
312 If its set to 0, DBIx::MoCo::DataBase uses DBI->connect instead of
313 DBI->connect_cached.
314  
315 DBIx::MoCo::DataBase->cache_connection(0);
316  
317 =item dsn
318  
319 Configures dsn(s). You can specify single dsn as string, multiple dsns as an array,
320 master/slave dsns as hash.
321  
322 If you specify multiple dsns, they will be rotated automatically in round-robin.
323 MoCo will use slave dsns when the sql begins with C<SELECT> if you set up slave(s).
324  
325 MyDataBase->dsn('dbi:mysql:dbname=test');
326 MyDataBase->dsn(['dbi:mysql:dbname=test;host=db1','dbi:mysql:dbname=test;host=db2']);
327 MyDataBase->dsn(
328 master => ['dbi:mysql:dbname=test;host=db1','dbi:mysql:dbname=test;host=db2'],
329 );
330 MyDataBase->dsn(
331 master => 'dbi:mysql:dbname=test;host=db1',
332 slave => ['dbi:mysql:dbname=test;host=db2','dbi:mysql:dbname=test;host=db3'],
333 );
334  
335 =back
336  
337 =head1 SEE ALSO
338  
339 L<DBIx::MoCo>, L<SQL::Abstract>
340  
341 =head1 AUTHOR
342  
343 Junya Kondo, E<lt>jkondo@hatena.comE<gt>
344  
345 =head1 COPYRIGHT AND LICENSE
346  
347 Copyright (C) Hatena Inc. All Rights Reserved.
348  
349 This library is free software; you may redistribute it and/or modify
350 it under the same terms as Perl itself.
351  
352 =cut
« MoCo/List.pm ↑ Summary MoCo/Fixture.pm »