convert from the bottom up
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Replicated / WithDSN.pm
index a6fe522..b389ce2 100644 (file)
@@ -1,11 +1,10 @@
 package DBIx::Class::Storage::DBI::Replicated::WithDSN;
 
-use Moose::Role;
-use Scalar::Util 'reftype';
+use Try::Tiny qw(try);
+use Scalar::Util ();
+use Role::Tiny;
 requires qw/_query_start/;
 
-use namespace::clean -except => 'meta';
-
 =head1 NAME
 
 DBIx::Class::Storage::DBI::Replicated::WithDSN - A DBI Storage Role with DSN
@@ -32,15 +31,18 @@ Add C<DSN: > to debugging output.
 around '_query_start' => sub {
   my ($method, $self, $sql, @bind) = @_;
 
-  my $dsn = eval { $self->dsn } || $self->_dbi_connect_info->[0];
+  my $dsn = (try { $self->dsn }) || $self->_dbi_connect_info->[0];
 
   my($op, $rest) = (($sql=~m/^(\w+)(.+)$/),'NOP', 'NO SQL');
   my $storage_type = $self->can('active') ? 'REPLICANT' : 'MASTER';
 
   my $query = do {
-    if ((reftype($dsn)||'') ne 'CODE') {
+    if ((Scalar::Util::reftype($dsn)||'') ne 'CODE') {
       "$op [DSN_$storage_type=$dsn]$rest";
     }
+    elsif (my $id = try { $self->id }) {
+      "$op [$storage_type=$id]$rest";
+    }
     else {
       "$op [$storage_type]$rest";
     }
@@ -55,7 +57,7 @@ L<DBIx::Class::Storage::DBI>
 
 =head1 AUTHOR
 
-John Napiorkowski <john.napiorkowski@takkle.com>
+John Napiorkowski <jjnapiork@cpan.org>
 
 =head1 LICENSE