[Bast-commits] r4374 - in DBIx-Class/0.08/branches/replication_dedux: lib/DBIx/Class t

jnapiorkowski at dev.catalyst.perl.org jnapiorkowski at dev.catalyst.perl.org
Fri May 9 18:00:46 BST 2008


Author: jnapiorkowski
Date: 2008-05-09 18:00:46 +0100 (Fri, 09 May 2008)
New Revision: 4374

Modified:
   DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Schema.pm
   DBIx-Class/0.08/branches/replication_dedux/t/93storage_replication.t
Log:
changed the way args are passed to a storage type that needs args so they can be in the form of a hash or array ref.  This plays nicer with Config::General for loading

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-05-09 15:53:45 UTC (rev 4373)
+++ DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Schema.pm	2008-05-09 17:00:46 UTC (rev 4374)
@@ -637,9 +637,9 @@
 
 =over 4
 
-=item Arguments: $storage_type|[$storage_type, \%args]
+=item Arguments: $storage_type|{$storage_type, \%args}
 
-=item Return Value: $storage_type|[$storage_type, \%args]
+=item Return Value: $storage_type|{$storage_type, \%args}
 
 =back
 
@@ -655,9 +655,11 @@
 
 If your storage type requires instantiation arguments, those are defined as a 
 second argument in the form of a hashref and the entire value needs to be
-wrapped into an arrayref.  See L<DBIx::Class::Storage::DBI::Replicated> for an
-example of this.
+wrapped into an arrayref or a hashref.  We support both types of refs here in
+order to play nice with your Config::[class] or your choice.
 
+See L<DBIx::Class::Storage::DBI::Replicated> for an example of this.
+
 =head2 connection
 
 =over 4
@@ -682,7 +684,7 @@
   return $self if !@info && $self->storage;
   
   my ($storage_class, $args) = ref $self->storage_type ? 
-    (@{$self->storage_type},{}) : ($self->storage_type, {});
+    ($self->_normalize_storage_type($self->storage_type),{}) : ($self->storage_type, {});
     
   $storage_class = 'DBIx::Class::Storage'.$storage_class
     if $storage_class =~ m/^::/;
@@ -696,6 +698,17 @@
   return $self;
 }
 
+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);
+	}
+}
+
 =head2 connect
 
 =over 4

Modified: DBIx-Class/0.08/branches/replication_dedux/t/93storage_replication.t
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/t/93storage_replication.t	2008-05-09 15:53:45 UTC (rev 4373)
+++ DBIx-Class/0.08/branches/replication_dedux/t/93storage_replication.t	2008-05-09 17:00:46 UTC (rev 4374)
@@ -61,14 +61,14 @@
         my $class = shift @_;
         
         my $schema = DBICTest->init_schema(
-            storage_type=>[
+            storage_type=>{
             	'::DBI::Replicated' => {
             		balancer_type=>'::Random',
                     balancer_args=>{
                     	auto_validate_every=>100,
                     },
             	}
-            ],
+            },
             deploy_args=>{
                    add_drop_table => 1,
             },




More information about the Bast-commits mailing list