DBIx-DataStore

 view release on metacpan or  search on metacpan

lib/DBIx/DataStore.pm  view on Meta::CPAN

        reader1:
            driver: Pg
            db: mydatabase
            host: db-2
            user: username
            schemas:
                - myschema
                - public
        secondreader:
            driver: Pg
            db: mydatabase
            host: 10.1.2.3
            port: 8306
            user: username
            schemas:
                - myschema
                - public

=head2 Explicit Hashref Configuration Example

    my $config = {
        default_reader      => '__random',
        reader_failover     => 1,
        flag_bad_readers    => 0,
        cache_connections   => 0,
        cache_statements    => 1,
        primary => {
            driver  => 'Pg',
            db      => 'mydatabase',
            host    => 'db-1',
            user    => 'username',
            pass    => 'password',
            schemas => ['myschema','public'],
            dbd_opts => {
                AutoCommit => 0,
            }
        },
        readers => {
            reader1 => {
                driver  => 'Pg',
                db      => 'mydatabase',
                host    => 'db-2',
                user    => 'username',
                schemas => ['myschema','public']
            },
            reader2 => {
                driver  => 'Pg',
                db      => 'mydatabase',
                host    => '10.1.2.3',
                port    => 8306,
                user    => 'username',
                schemas => ['myschema','public']
            }
        }
    };
    my $db = DBIx::DataStore->new({ config => $config });

=head2 Configuring Database Passwords

Because DBIx::DataStore uses the normal DBI/DBD layers underneath, all the
usual methods of locating and presenting database credentials to the
appropriate database server are available.  This includes methods such as the
C<.pgpass> file for PostgreSQL and equivalents for other RDBMSes. If your
DBIx::DataStore configuration does not include a C<pass> attribute for a given
database host, these alternate methods will be used as long as they are
properly configured.

=head1 SEE ALSO

L<Data::Page>, L<DBI>, L<YAML::Syck>

=head1 AUTHORS

Jon Sime E<lt>jonsime@gmail.comE<gt>,
Buddy Burden E<lt>buddy@barefoot.netE<gt>

=head1 LICENSE

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=cut

my $HASH_PH = qr/\?\?\?/;
my $ARRAY_PH = $HASH_PH;

my $USE_PAGER = 1;

# some "true" values/strings reused in a few places (mostly submodules)
our %TV = map { $_ => 1 } qw( 1 yes true on enable enabled );
# same thing, but for "false"
our %FV = map { $_ => 1 } qw( 0 no false off disable disabled );

sub import {
    my ($pkg, %t) = @_;

    foreach (keys %t) {
        $t{lc($_)} = lc($t{$_});
        delete $t{$_} unless lc($_) eq $_;
    }

    # set up debugging and logger
    $t{'debug'} = $ENV{'DATASTORE_DEBUG'} if (!defined $t{'debug'} || $t{'debug'} !~ /^\d+$/o)
        && defined $ENV{'DATASTORE_DEBUG'} && $ENV{'DATASTORE_DEBUG'} =~ /^\d+$/o;
    $t{'debug'} = 0 unless defined $t{'debug'} && $t{'debug'} =~ /^\d+$/o;
    eval("use DBIx::DataStore::Debug ($t{'debug'});");

    if (defined $t{'paging'}) {
        if (exists $TV{lc($t{'paging'})}) { #load Data::Page now
            $USE_PAGER = 1;
            eval("use Data::Page");
        } elsif (exists $FV{lc($t{'paging'})}) { #don't ever load Data::Page
            $USE_PAGER = 0;
        } else { # auto-loading of Data::Page on first use
            $USE_PAGER = -1;
        }
    }

    # call the config loader submodule
    $t{'use_home'} = 0 if !defined $t{'use_home'} || $t{'use_home'} !~ /^\d+$/o;
    eval("use DBIx::DataStore::Config ('$t{'config'}', $t{'use_home'});")



( run in 1.764 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )