[Bast-commits] r4473 - in DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class: . Storage/DBI Storage/DBI/Replicated

jnapiorkowski at dev.catalyst.perl.org jnapiorkowski at dev.catalyst.perl.org
Thu Jun 5 17:28:23 BST 2008


Author: jnapiorkowski
Date: 2008-06-05 17:28:23 +0100 (Thu, 05 Jun 2008)
New Revision: 4473

Modified:
   DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Schema.pm
   DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated.pm
   DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Balancer.pm
   DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm
   DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Replicant.pm
Log:
all your tabs belong to spaces

Modified: DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Schema.pm
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Schema.pm	2008-06-05 14:28:00 UTC (rev 4472)
+++ DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Schema.pm	2008-06-05 16:28:23 UTC (rev 4473)
@@ -699,14 +699,14 @@
 }
 
 sub _normalize_storage_type {
-	my ($self, $storage_type) = @_;
-	if(ref $storage_type eq 'ARRAY') {
-		return @$storage_type;
-	} elsif(ref $storage_type eq 'HASH') {
-		return %$storage_type;
-	} else {
-		$self->throw_exception('Unsupported REFTYPE given: '. ref $storage_type);
-	}
+    my ($self, $storage_type) = @_;
+    if(ref $storage_type eq 'ARRAY') {
+        return @$storage_type;
+    } elsif(ref $storage_type eq 'HASH') {
+        return %$storage_type;
+    } else {
+        $self->throw_exception('Unsupported REFTYPE given: '. ref $storage_type);
+    }
 }
 
 =head2 connect

Modified: DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Balancer.pm
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Balancer.pm	2008-06-05 14:28:00 UTC (rev 4472)
+++ DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Balancer.pm	2008-06-05 16:28:23 UTC (rev 4473)
@@ -124,9 +124,9 @@
 =cut
 
 around 'next_storage' => sub {
-	my ($next_storage, $self, @args) = @_;
-	my $now = time;
-	
+    my ($next_storage, $self, @args) = @_;
+    my $now = time;
+    
     ## Do we need to validate the replicants?
     if(
        $self->has_auto_validate_every && 
@@ -137,7 +137,7 @@
     
     ## Get a replicant, or the master if none
     my $next = $self->$next_storage(@args);
-    return $next ? $next:$self->master;	
+    return $next ? $next:$self->master; 
 };
 
 =head2 before: select

Modified: DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm	2008-06-05 14:28:00 UTC (rev 4472)
+++ DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm	2008-06-05 16:28:23 UTC (rev 4473)
@@ -76,8 +76,8 @@
     required=>1,
     default=>'DBIx::Class::Storage::DBI',
     handles=>{
-    	'create_replicant' => 'new',
-    },	
+        'create_replicant' => 'new',
+    },  
 );
 
 =head2 replicants
@@ -125,12 +125,12 @@
     isa=>'HashRef[DBIx::Class::Storage::DBI]',
     default=>sub {{}},
     provides  => {
-		'set' => 'set_replicant',
-		'get' => 'get_replicant',            
-		'empty' => 'has_replicants',
-		'count' => 'num_replicants',
-		'delete' => 'delete_replicant',
-	},
+        'set' => 'set_replicant',
+        'get' => 'get_replicant',            
+        'empty' => 'has_replicants',
+        'count' => 'num_replicants',
+        'delete' => 'delete_replicant',
+    },
 );
 
 =head1 METHODS
@@ -146,23 +146,23 @@
 =cut
 
 sub connect_replicants {
-	my $self = shift @_;
-	my $schema = shift @_;
-	
-	my @newly_created = ();
-	foreach my $connect_info (@_) {
-		
-		my $replicant = $self->create_replicant($schema);
-		$replicant->connect_info($connect_info);	
-		$replicant->ensure_connected;
-		DBIx::Class::Storage::DBI::Replicated::Replicant->meta->apply($replicant);
-		
-		my ($key) = ($connect_info->[0]=~m/^dbi\:.+\:(.+)$/);
-		$self->set_replicant( $key => $replicant);	
-		push @newly_created, $replicant;
-	}
-	
-	return @newly_created;
+    my $self = shift @_;
+    my $schema = shift @_;
+    
+    my @newly_created = ();
+    foreach my $connect_info (@_) {
+        
+        my $replicant = $self->create_replicant($schema);
+        $replicant->connect_info($connect_info);    
+        $replicant->ensure_connected;
+        DBIx::Class::Storage::DBI::Replicated::Replicant->meta->apply($replicant);
+        
+        my ($key) = ($connect_info->[0]=~m/^dbi\:.+\:(.+)$/);
+        $self->set_replicant( $key => $replicant);  
+        push @newly_created, $replicant;
+    }
+    
+    return @newly_created;
 }
 
 =head2 connected_replicants
@@ -171,9 +171,9 @@
 return the number of replicants.  So you can do stuff like:
 
     if( my $num_connected = $storage->has_connected_replicants ) {
-    	print "I have $num_connected connected replicants";
+        print "I have $num_connected connected replicants";
     } else {
-    	print "Sorry, no replicants.";
+        print "Sorry, no replicants.";
     }
 
 This method will actually test that each replicant in the L</replicants> hashref
@@ -182,10 +182,10 @@
 =cut
 
 sub connected_replicants {
-	my $self = shift @_;
-	return sum( map {
-		$_->connected ? 1:0
-	} $self->all_replicants );
+    my $self = shift @_;
+    return sum( map {
+        $_->connected ? 1:0
+    } $self->all_replicants );
 }
 
 =head2 active_replicants
@@ -241,10 +241,10 @@
             $replicant->lag_behind_master <= $self->maximum_lag &&
             $replicant->ensure_connected
         ) {
-        	## TODO:: Hook debug for this
+            ## TODO:: Hook debug for this
             $replicant->active(1)
         } else {
-        	## TODO:: Hook debug for this
+            ## TODO:: Hook debug for this
             $replicant->active(0);
         }
     }

Modified: DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Replicant.pm
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Replicant.pm	2008-06-05 14:28:00 UTC (rev 4472)
+++ DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Replicant.pm	2008-06-05 16:28:23 UTC (rev 4473)
@@ -58,12 +58,11 @@
 =cut
 
 around '_query_start' => sub {
-	my ($method, $self, $sql, @bind) = @_;
-	my $dsn = $self->connect_info->[0];
-	$self->$method("DSN: $dsn SQL: $sql", @bind);
+    my ($method, $self, $sql, @bind) = @_;
+    my $dsn = $self->connect_info->[0];
+    $self->$method("DSN: $dsn SQL: $sql", @bind);
 };
 
-
 =head1 AUTHOR
 
 John Napiorkowski <john.napiorkowski at takkle.com>

Modified: DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated.pm
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated.pm	2008-06-05 14:28:00 UTC (rev 4472)
+++ DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated.pm	2008-06-05 16:28:23 UTC (rev 4473)
@@ -75,7 +75,7 @@
     isa=>'ClassName',
     lazy_build=>1,
     handles=>{
-    	'create_pool' => 'new',
+        'create_pool' => 'new',
     },
 );
 
@@ -107,7 +107,7 @@
     isa=>'ClassName',
     lazy_build=>1,
     handles=>{
-    	'create_balancer' => 'new',
+        'create_balancer' => 'new',
     },
 );
 
@@ -257,8 +257,8 @@
     ## Hate to do it this way, but can't seem to get advice on the attribute working right
     ## maybe we can do a type and coercion for it. 
     if( $storage_type_args->{balancer_type} && $storage_type_args->{balancer_type}=~m/^::/) {
-    	$storage_type_args->{balancer_type} = 'DBIx::Class::Storage::DBI::Replicated::Balancer'.$storage_type_args->{balancer_type};
-    	eval "require $storage_type_args->{balancer_type}";
+        $storage_type_args->{balancer_type} = 'DBIx::Class::Storage::DBI::Replicated::Balancer'.$storage_type_args->{balancer_type};
+        eval "require $storage_type_args->{balancer_type}";
     }
     
     return $class->meta->new_object(
@@ -275,7 +275,7 @@
 =cut
 
 sub _build_master {
-	DBIx::Class::Storage::DBI->new;
+    DBIx::Class::Storage::DBI->new;
 }
 
 =head2 _build_pool_type
@@ -295,7 +295,7 @@
 =cut
 
 sub _build_pool {
-	my $self = shift @_;
+    my $self = shift @_;
     $self->create_pool(%{$self->pool_args});
 }
 
@@ -321,7 +321,8 @@
     $self->create_balancer(
         pool=>$self->pool, 
         master=>$self->master,
-        %{$self->balancer_args},);
+        %{$self->balancer_args},
+    );
 }
 
 =head2 _build_write_handler
@@ -354,8 +355,8 @@
 =cut
 
 around 'connect_replicants' => sub {
-	my ($method, $self, @args) = @_;
-	$self->$method($self->schema, @args);
+    my ($method, $self, @args) = @_;
+    $self->$method($self->schema, @args);
 };
 
 =head2 all_storages
@@ -367,12 +368,12 @@
 =cut
 
 sub all_storages {
-	my $self = shift @_;
-	
-	return grep {defined $_ && blessed $_} (
-	   $self->master,
-	   $self->replicants,
-	);
+    my $self = shift @_;
+    
+    return grep {defined $_ && blessed $_} (
+       $self->master,
+       $self->replicants,
+    );
 }
 
 =head2 execute_reliably ($coderef, ?@args)
@@ -399,7 +400,7 @@
 
 sub execute_reliably {
     my ($self, $coderef, @args) = @_;
-	
+    
     unless( ref $coderef eq 'CODE') {
         $self->throw_exception('Second argument must be a coderef');
     }
@@ -418,14 +419,14 @@
     my $want_array = wantarray;
     
     eval {
-	    if($want_array) {
-	        @result = $coderef->(@args);
-	    }
-	    elsif(defined $want_array) {
-	        ($result[0]) = ($coderef->(@args));
-	    } else {
-	        $coderef->(@args);
-	    }    	
+        if($want_array) {
+            @result = $coderef->(@args);
+        }
+        elsif(defined $want_array) {
+            ($result[0]) = ($coderef->(@args));
+        } else {
+            $coderef->(@args);
+        }       
     };
     
     ##Reset to the original state
@@ -437,7 +438,7 @@
     if($@) {
         $self->throw_exception("coderef returned an error: $@");
     } else {
-    	return $want_array ? @result : $result[0];
+        return $want_array ? @result : $result[0];
     }
 }
 
@@ -449,11 +450,11 @@
 =cut
 
 sub set_reliable_storage {
-	my $self = shift @_;
-	my $schema = $self->schema;
-	my $write_handler = $self->schema->storage->write_handler;
-	
-	$schema->storage->read_handler($write_handler);
+    my $self = shift @_;
+    my $schema = $self->schema;
+    my $write_handler = $self->schema->storage->write_handler;
+    
+    $schema->storage->read_handler($write_handler);
 }
 
 =head2 set_balanced_storage
@@ -481,7 +482,7 @@
 
 around 'txn_do' => sub {
     my($txn_do, $self, $coderef, @args) = @_;
-    $self->execute_reliably(sub {$self->$txn_do($coderef, @args)});	
+    $self->execute_reliably(sub {$self->$txn_do($coderef, @args)}); 
 };
 
 =head2 reload_row ($row)
@@ -492,10 +493,10 @@
 =cut
 
 around 'reload_row' => sub {
-	my ($reload_row, $self, $row) = @_;
-	return $self->execute_reliably(sub {
-		return $self->$reload_row(shift);
-	}, $row);
+    my ($reload_row, $self, $row) = @_;
+    return $self->execute_reliably(sub {
+        return $self->$reload_row(shift);
+    }, $row);
 };
 
 =head2 connected
@@ -505,11 +506,11 @@
 =cut
 
 sub connected {
-	my $self = shift @_;
-	
-	return
-	   $self->master->connected &&
-	   $self->pool->connected_replicants;
+    my $self = shift @_;
+    
+    return
+       $self->master->connected &&
+       $self->pool->connected_replicants;
 }
 
 =head2 ensure_connected
@@ -571,10 +572,10 @@
 =cut
 
 sub set_schema {
-	my $self = shift @_;
-	foreach my $source ($self->all_storages) {
-		$source->set_schema(@_);
-	}
+    my $self = shift @_;
+    foreach my $source ($self->all_storages) {
+        $source->set_schema(@_);
+    }
 }
 
 =head2 debug




More information about the Bast-commits mailing list