From: Peter Rabbitson Date: Wed, 10 Apr 2013 03:01:24 +0000 (+0200) Subject: Cleanup logic of _determine_driver - do not fire unless we have conninfo X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d87929a4221da691151ac8849a658a5d363d88f7;p=dbsrgits%2FDBIx-Class-Historic.git Cleanup logic of _determine_driver - do not fire unless we have conninfo Also switch some connection init warnings s/carp/carp_unique/ --- diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index a70da84..16850a3 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -119,9 +119,11 @@ for my $meth (@rdbms_specific_methods) { # would e.g. be setting a default for an inherited accessor ref $_[0] and - ! $_[0]->_driver_determined + ! $_[0]->{_driver_determined} and ! $_[0]->{_in_determine_driver} + and + ($_[0]->_dbi_connect_info||[])->[0] ) { $_[0]->_determine_driver; @@ -625,13 +627,13 @@ sub connect_info { my @args = @{ $info->{arguments} }; if (keys %attrs and ref $args[0] ne 'CODE') { - carp + carp_unique ( 'You provided explicit AutoCommit => 0 in your connection_info. ' . 'This is almost universally a bad idea (see the footnotes of ' . 'DBIx::Class::Storage::DBI for more info). If you still want to ' . 'do this you can set $ENV{DBIC_UNSAFE_AUTOCOMMIT_OK} to disable ' . 'this warning.' - if ! $attrs{AutoCommit} and ! $ENV{DBIC_UNSAFE_AUTOCOMMIT_OK}; + ) if ! $attrs{AutoCommit} and ! $ENV{DBIC_UNSAFE_AUTOCOMMIT_OK}; push @args, \%attrs if keys %attrs; } @@ -951,13 +953,13 @@ sub sql_maker { || do { my $s_class = (ref $self) || $self; - carp ( + carp_unique ( "Your storage class ($s_class) does not set sql_limit_dialect and you " . 'have not supplied an explicit limit_dialect in your connection_info. ' . 'DBIC will attempt to use the GenericSubQ dialect, which works on most ' . 'databases but can be (and often is) painfully slow. ' - . "Please file an RT ticket against '$s_class' ." - ); + . "Please file an RT ticket against '$s_class'" + ) if $self->_dbi_connect_info->[0]; 'GenericSubQ'; } @@ -968,7 +970,7 @@ sub sql_maker { if ($opts{quote_names}) { $quote_char = (delete $opts{quote_char}) || $self->sql_quote_char || do { my $s_class = (ref $self) || $self; - carp ( + carp_unique ( "You requested 'quote_names' but your storage class ($s_class) does " . 'not explicitly define a default sql_quote_char and you have not ' . 'supplied a quote_char as part of your connection_info. DBIC will ' @@ -1371,8 +1373,8 @@ sub _do_query { sub _connect { my ($self, @info) = @_; - $self->throw_exception("You failed to provide any connection info") - if !@info; + $self->throw_exception("You did not provide any connection_info") + if ( ! defined $info[0] and ! $ENV{DBI_DSN} and ! $ENV{DBI_DRIVER} ); my ($old_connect_via, $dbh); diff --git a/t/storage/base.t b/t/storage/base.t index 948d49a..b647ade 100644 --- a/t/storage/base.t +++ b/t/storage/base.t @@ -146,6 +146,31 @@ for my $type (keys %$invocations) { ); } +# make sure connection-less storages do not throw on _determine_driver +{ + my $s = DBICTest::Schema->connect; + is_deeply ( + $s->storage->connect_info, + [], + 'Starting with no connection info', + ); + + isa_ok( + $s->storage->sql_maker, + 'DBIx::Class::SQLMaker', + 'Getting back an SQLMaker succesfully', + ); + + ok (! $s->storage->_driver_determined, 'Driver undetermined'); + + ok (! $s->storage->connected, 'Storage does not appear connected'); + + throws_ok { + $s->storage->ensure_connected + } qr/You did not provide any connection_info/, + 'sensible exception on empty conninfo connect' +} + done_testing; 1;