all your tabs belong to spaces
John Napiorkowski [Thu, 5 Jun 2008 16:28:23 +0000 (16:28 +0000)]
lib/DBIx/Class/Schema.pm
lib/DBIx/Class/Storage/DBI/Replicated.pm
lib/DBIx/Class/Storage/DBI/Replicated/Balancer.pm
lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm
lib/DBIx/Class/Storage/DBI/Replicated/Replicant.pm

index a51ab96..55cf8fc 100644 (file)
@@ -699,14 +699,14 @@ sub connection {
 }
 
 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
index a21c413..03a3fcd 100644 (file)
@@ -75,7 +75,7 @@ has 'pool_type' => (
     isa=>'ClassName',
     lazy_build=>1,
     handles=>{
-       'create_pool' => 'new',
+        'create_pool' => 'new',
     },
 );
 
@@ -107,7 +107,7 @@ has 'balancer_type' => (
     isa=>'ClassName',
     lazy_build=>1,
     handles=>{
-       'create_balancer' => 'new',
+        'create_balancer' => 'new',
     },
 );
 
@@ -257,8 +257,8 @@ sub new {
     ## 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 @@ Lazy builder for the L</master> attribute.
 =cut
 
 sub _build_master {
-       DBIx::Class::Storage::DBI->new;
+    DBIx::Class::Storage::DBI->new;
 }
 
 =head2 _build_pool_type
@@ -295,7 +295,7 @@ Lazy builder for the L</pool> attribute.
 =cut
 
 sub _build_pool {
-       my $self = shift @_;
+    my $self = shift @_;
     $self->create_pool(%{$self->pool_args});
 }
 
@@ -321,7 +321,8 @@ sub _build_balancer {
     $self->create_balancer(
         pool=>$self->pool, 
         master=>$self->master,
-        %{$self->balancer_args},);
+        %{$self->balancer_args},
+    );
 }
 
 =head2 _build_write_handler
@@ -354,8 +355,8 @@ top of the args, since L<DBIx::Storage::DBI> needs it.
 =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 @@ replicants.
 =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 @@ inserted something and need to get a resultset including it, etc.
 
 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 @@ sub execute_reliably {
     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 @@ sub execute_reliably {
     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 @@ write are sent to the master
 =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 @@ L</execute_reliably> method.
 
 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 @@ the master storage.
 =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 @@ Check that the master and at least one of the replicants is connected.
 =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 @@ Set the schema object for all existing storages
 =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
index ed7007d..3e4755d 100644 (file)
@@ -124,9 +124,9 @@ or just just forgot to create them :)
 =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 @@ around 'next_storage' => sub {
     
     ## 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
index bf46823..f6acf90 100644 (file)
@@ -76,8 +76,8 @@ has 'replicant_type' => (
     required=>1,
     default=>'DBIx::Class::Storage::DBI',
     handles=>{
-       'create_replicant' => 'new',
-    }, 
+        'create_replicant' => 'new',
+    },  
 );
 
 =head2 replicants
@@ -125,12 +125,12 @@ has 'replicants' => (
     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 @@ L</replicants> attribute.
 =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 @@ Returns true if there are connected replicants.  Actually is overloaded to
 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 @@ is actually connected, try not to hit this 10 times a second.
 =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 @@ sub validate_replicants {
             $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);
         }
     }
index e1e7f8d..7449146 100644 (file)
@@ -58,12 +58,11 @@ advice iof the _query_start method to add more debuggin
 =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@takkle.com>