From: John Napiorkowski Date: Fri, 9 May 2008 17:00:46 +0000 (+0000) Subject: changed the way args are passed to a storage type that needs args so they can be... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=161fb22350bdfb511af2cc96d2a556a4296c20e8;p=dbsrgits%2FDBIx-Class-Historic.git 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 --- diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index c3ce0e6..a51ab96 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -637,9 +637,9 @@ sub setup_connection_class { =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,8 +655,10 @@ C<::DBI::Sybase::MSSQL>. 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 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 for an example of this. =head2 connection @@ -682,7 +684,7 @@ sub connection { 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 @@ sub connection { 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 diff --git a/t/93storage_replication.t b/t/93storage_replication.t index 1156a24..7617af3 100644 --- a/t/93storage_replication.t +++ b/t/93storage_replication.t @@ -61,14 +61,14 @@ TESTSCHEMACLASSES: { 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, },