MPMinus
view release on metacpan or search on metacpan
lib/MPMinus/Store/MultiStore.pm view on Meta::CPAN
package MPMinus::Store::MultiStore; # $Id: MultiStore.pm 273 2019-05-08 10:44:56Z minus $
use strict;
use utf8;
=encoding utf-8
=head1 NAME
MPMinus::Store::MultiStore - Multistoring MPMinus::Store::DBI interface
=head1 VERSION
Version 1.05
=head1 SYNOPSIS
use MPMinus::Store::MultiStore;
# Multistoring
my $mso = new MPMinus::Store::MultiStore (
-mso => {
foo => {
-dsn => 'DBI:mysql:database=TEST;host=192.168.1.1',
-user => 'login',
-pass => 'password',
-attr => {
mysql_enable_utf8 => 1,
RaiseError => 0,
PrintError => 0,
},
},
bar => {
-dsn => 'DBI:Oracle:SID',
-user => 'login',
-pass => 'password',
-attr => {
RaiseError => 0,
PrintError => 0,
},
},
},
);
my @stores = $mso->stores; # foo, bar
$mso->set(baz => new MPMinus::Store::DBI( {
-dsn => 'DBI:Oracle:BAZSID',
-user => 'login',
-pass => 'password',
-attr => {
RaiseError => 0,
PrintError => 0,
},
})
);
my @stores = $mso->stores; # foo, bar, baz
my $foo = $mso->get('foo');
my $foo = $mso->store('foo');
my $foo = $mso->foo;
=head1 DESCRIPTION
Multistoring MPMinus::Store::DBI interface
See L<MPMinus::Store::DBI>
=head2 new
my $mso = new MPMinus::Store::MultiStore (
-mso => { ... },
);
Returns MultiStore object
See also L<MPMinus::Store::DBI>
=head1 METHODS
=over 8
=item B<get, store>
my $foo = $mso->get('foo');
my $foo = $mso->store('foo');
my $foo = $mso->foo;
lib/MPMinus/Store/MultiStore.pm view on Meta::CPAN
my @stores = $mso->stores; # foo, bar, baz
Returns current connections as list (array)
=back
=head1 EXAMPLE
package MPM::foo::Handlers;
use strict;
use MPMinus::Store::MultiStore;
use MPMinus::MainTools qw/ msoconf2args /;
sub InitHandler {
my $pkg = shift;
my $m = shift;
# MSO Database Nodes
if ($m->multistore) {
my $mso = $m->multistore;
foreach ($mso->stores) {
$mso->get($_)->reconnect unless $mso->get($_)->ping;
}
} else {
$m->set( multistore => new MPMinus::Store::MultiStore (
-mso => { msoconf2args($m->conf('store')) },
)
);
}
return __PACKAGE__->SUPER::InitHandler($m);
}
...
package MPM::foo::Test;
use strict;
sub response {
my $m = shift;
my $mso = $m->multistore;
my $data = $mso->foo->errstr
? $mso->foo->errstr
: $mso->foo->field('select sysdate() from dual');
...
return Apache2::Const::OK;
}
In conf/mso.conf file:
<store foo>
dsn DBI:mysql:database=TEST;host=192.168.1.1
user login
pass password
<Attr>
mysql_enable_utf8 1
RaiseError 0
PrintError 0
</Attr>
</store>
<store bar>
dsn DBI:Oracle:FOOSID
user login
pass password
connect_to 10
request_to 50
<Attr>
RaiseError 0
PrintError 0
</Attr>
</store>
<store baz>
dsn DBI:Oracle:BARSID
user login
pass password
<Attr>
RaiseError 0
PrintError 0
</Attr>
</store>
=head1 HISTORY
=over 8
=item B<1.00 13.11.2010>
Init version
=item B<1.01 22.12.2010>
Added method for getting list of stores
=item B<1.02 Wed Apr 24 14:53:38 2013 MSK>
General refactoring
=back
See C<CHANGES> file
=head1 DEPENDENCIES
L<MPMinus::Store::DBI>
=head1 TO DO
See C<TODO> file
=head1 BUGS
* none noted
=head1 SEE ALSO
L<MPMinus::Store::DBI>
( run in 2.999 seconds using v1.01-cache-2.11-cpan-437f7b0c052 )