Skip to content

Commit

Permalink
use DBIx::DSN::Resolver::Cached
Browse files Browse the repository at this point in the history
  • Loading branch information
lestrrat committed Jan 20, 2014
1 parent ee9f254 commit 6b562be
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions cpanfile
Expand Up @@ -5,6 +5,7 @@ requires 'Data::FormValidator' => 0;
requires 'Data::Localize' => 0;
requires 'Digest::MurmurHash' => 0;
requires 'DBI' => 0;
requires 'DBIx::DSN::Resolver::Cached' => '0.04';
requires 'DBD::mysql' => 0;
requires 'Email::MIME' => 0;
requires 'Email::Send' => 0;
Expand Down
14 changes: 13 additions & 1 deletion etc/container.pl
@@ -1,4 +1,5 @@
use strict;
use DBIx::DSN::Resolver::Cached;
use Furl::HTTP;
use String::Urandom;
use Cache::Memcached::Fast;
Expand Down Expand Up @@ -40,13 +41,24 @@
my $config = $c->get('config');
Cache::Memcached::Fast->new( $config->{'Memcached'} );
};
register DSNResolver => DBIx::DSN::Resolver::Cached->new(
ttl => 30,
negative_ttl => 5
);

my $register_dbh = sub {
my ($key) = @_;
register $key => sub {
my $c = shift;
my $config = $c->get('config');
my $dbh = DBI->connect( @{$config->{$key}} );

$resolver = $c->get('DSNResolver');

my @connect_info = @{$config->{$key}}
my $dsn = $resolver->resolv($connect_info[0])
$connect_info[0] = $dsn;

my $dbh = DBI->connect(@connect_info);
$dbh->{HandleError} = sub {
our @CARP_NOT = ('STF::API::WithDBI');
Carp::croak(shift) };
Expand Down

0 comments on commit 6b562be

Please sign in to comment.