From: Peter Rabbitson Date: Fri, 12 Feb 2010 12:45:18 +0000 (+0000) Subject: Move sqlt dephandling to Optional::Deps X-Git-Tag: v0.08119~14^2~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2527233b404455c2114f90da8041f42cd957f541;p=dbsrgits%2FDBIx-Class.git Move sqlt dephandling to Optional::Deps --- diff --git a/lib/DBIx/Class.pm b/lib/DBIx/Class.pm index 60a4f75..5da8951 100644 --- a/lib/DBIx/Class.pm +++ b/lib/DBIx/Class.pm @@ -6,6 +6,8 @@ use warnings; use MRO::Compat; use mro 'c3'; +use DBIx::Class::Optional::Dependencies; + use vars qw($VERSION); use base qw/DBIx::Class::Componentised Class::Accessor::Grouped/; use DBIx::Class::StartupCheck; diff --git a/lib/DBIx/Class/Schema/Versioned.pm b/lib/DBIx/Class/Schema/Versioned.pm index d42b897..10edb01 100644 --- a/lib/DBIx/Class/Schema/Versioned.pm +++ b/lib/DBIx/Class/Schema/Versioned.pm @@ -617,8 +617,9 @@ sub _create_db_to_schema_diff { return; } - $self->throw_exception($self->storage->_sqlt_version_error) - if (not $self->storage->_sqlt_version_ok); + unless (DBIx::Class::Optional::Dependencies->req_ok_for ('deploy')) { + $self->throw_exception("Unable to proceed without " . DBIx::Class::Optional::Dependencies->req_missing_for ('deploy') ); + } my $db_tr = SQL::Translator->new({ add_drop_table => 1, diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 32c6ed1..0030431 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -16,11 +16,6 @@ use List::Util(); use Data::Dumper::Concise(); use Sub::Name (); -# what version of sqlt do we require if deploy() without a ddl_dir is invoked -# when changing also adjust the corresponding author_require in Makefile.PL -my $minimum_sqlt_version = '0.11002'; - - __PACKAGE__->mk_group_accessors('simple' => qw/_connect_info _dbi_connect_info _dbh _sql_maker _sql_maker_opts _conn_pid _conn_tid transaction_depth _dbh_autocommit _driver_determined savepoints/ @@ -2251,8 +2246,9 @@ sub create_ddl_dir { %{$sqltargs || {}} }; - $self->throw_exception("Can't create a ddl file without SQL::Translator: " . $self->_sqlt_version_error) - if !$self->_sqlt_version_ok; + unless (DBIx::Class::Optional::Dependencies->req_ok_for ('deploy')) { + $self->throw_exception("Can't create a ddl file without " . DBIx::Class::Optional::Dependencies->req_missing_for ('deploy') ); + } my $sqlt = SQL::Translator->new( $sqltargs ); @@ -2394,8 +2390,9 @@ sub deployment_statements { return join('', @rows); } - $self->throw_exception("Can't deploy without either SQL::Translator or a ddl_dir: " . $self->_sqlt_version_error ) - if !$self->_sqlt_version_ok; + unless (DBIx::Class::Optional::Dependencies->req_ok_for ('deploy') ) { + $self->throw_exception("Can't deploy without a ddl_dir or " . DBIx::Class::Optional::Dependencies->req_missing_for ('deploy') ); + } # sources needs to be a parser arg, but for simplicty allow at top level # coming in @@ -2519,33 +2516,6 @@ sub lag_behind_master { return; } -# SQLT version handling -{ - my $_sqlt_version_ok; # private - my $_sqlt_version_error; # private - - sub _sqlt_version_ok { - if (!defined $_sqlt_version_ok) { - eval "use SQL::Translator $minimum_sqlt_version"; - if ($@) { - $_sqlt_version_ok = 0; - $_sqlt_version_error = $@; - } - else { - $_sqlt_version_ok = 1; - } - } - return $_sqlt_version_ok; - } - - sub _sqlt_version_error { - shift->_sqlt_version_ok unless defined $_sqlt_version_ok; - return $_sqlt_version_error; - } - - sub _sqlt_minimum_version { $minimum_sqlt_version }; -} - =head2 relname_to_table_alias =over 4 diff --git a/t/86sqlt.t b/t/86sqlt.t index 26e1fc2..a832325 100644 --- a/t/86sqlt.t +++ b/t/86sqlt.t @@ -6,10 +6,10 @@ use lib qw(t/lib); use DBICTest; BEGIN { - require DBIx::Class::Storage::DBI; + require DBIx::Class; plan skip_all => - 'Test needs SQL::Translator ' . DBIx::Class::Storage::DBI->_sqlt_minimum_version - if not DBIx::Class::Storage::DBI->_sqlt_version_ok; + 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('deploy') + unless DBIx::Class::Optional::Dependencies->req_ok_for ('deploy') } my $schema = DBICTest->init_schema (no_deploy => 1); diff --git a/t/94versioning.t b/t/94versioning.t index 58c25d3..685809b 100644 --- a/t/94versioning.t +++ b/t/94versioning.t @@ -22,10 +22,10 @@ BEGIN { || plan skip_all => 'Test needs Time::HiRes'; Time::HiRes->import(qw/time sleep/); - require DBIx::Class::Storage::DBI; + require DBIx::Class; plan skip_all => - 'Test needs SQL::Translator ' . DBIx::Class::Storage::DBI->_sqlt_minimum_version - if not DBIx::Class::Storage::DBI->_sqlt_version_ok; + 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('deploy') + unless DBIx::Class::Optional::Dependencies->req_ok_for ('deploy') } use lib qw(t/lib); diff --git a/t/99dbic_sqlt_parser.t b/t/99dbic_sqlt_parser.t index 628f3cf..7487c72 100644 --- a/t/99dbic_sqlt_parser.t +++ b/t/99dbic_sqlt_parser.t @@ -9,10 +9,10 @@ use DBICTest::Schema; use Scalar::Util (); BEGIN { - require DBIx::Class::Storage::DBI; + require DBIx::Class; plan skip_all => - 'Test needs SQL::Translator ' . DBIx::Class::Storage::DBI->_sqlt_minimum_version - if not DBIx::Class::Storage::DBI->_sqlt_version_ok; + 'Test needs ' . DBIx::Class::Optional::Dependencies->req_missing_for ('deploy') + unless DBIx::Class::Optional::Dependencies->req_ok_for ('deploy') } # Test for SQLT-related leaks