more noise debugging messages if debug is on, minor doc tweaks, changes so that the...
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Replicated / Balancer.pm
index 316653a..8af899c 100644 (file)
@@ -5,7 +5,7 @@ requires 'next_storage';
 
 =head1 NAME
 
-DBIx::Class::Storage::DBI::Replicated::Balancer; A Software Load Balancer 
+DBIx::Class::Storage::DBI::Replicated::Balancer - A Software Load Balancer 
 
 =head1 SYNOPSIS
 
@@ -126,18 +126,22 @@ or just just forgot to create them :)
 around 'next_storage' => sub {
   my ($next_storage, $self, @args) = @_;
   my $now = time;
-    
+
   ## Do we need to validate the replicants?
   if(
      $self->has_auto_validate_every && 
      ($self->auto_validate_every + $self->pool->last_validated) <= $now
-  ) {
+  ) {   
       $self->pool->validate_replicants;
   }
-    
+
   ## Get a replicant, or the master if none
-  my $next = $self->$next_storage(@args);
-  return $next ? $next:$self->master; 
+  if(my $next = $self->$next_storage(@args)) {
+    return $next;
+  } else {
+    $self->master->debugobj->print("No Replicants validate, falling back to master reads. ");
+    return $self->master;
+  }
 };
 
 =head2 increment_storage
@@ -184,10 +188,10 @@ around 'select_single' => sub {
   my ($select_single, $self, @args) = @_;
   
   if (my $forced_pool = $args[-1]->{force_pool}) {
-       delete $args[-1]->{force_pool};
-       return $self->_get_forced_pool($forced_pool)->select_single(@args); 
+    delete $args[-1]->{force_pool};
+    return $self->_get_forced_pool($forced_pool)->select_single(@args); 
   } else {
-       $self->increment_storage;
+    $self->increment_storage;
     return $self->$select_single(@args);
   }
 };