From: Peter Rabbitson Date: Wed, 2 Sep 2009 09:20:25 +0000 (+0000) Subject: Centralize handling of minimum sqlt version to DBIx::Class X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7f6f5b6903a37eb52b4e08398ac4ce64ce35f8e1;p=dbsrgits%2FDBIx-Class-Historic.git Centralize handling of minimum sqlt version to DBIx::Class Bump version to the latest unborked sqlt (still just a recommend) --- diff --git a/Makefile.PL b/Makefile.PL index 59ec4b1..8151718 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -52,7 +52,8 @@ my %replication_requires = ( 'Hash::Merge', => '0.11', ); -my $sqlt_recommends = '0.09004'; +# when changing also adjust $DBIx::Class::minimum_sqlt_version +my $sqlt_recommends = '0.11002'; recommends 'SQL::Translator' => $sqlt_recommends; diff --git a/lib/DBIx/Class.pm b/lib/DBIx/Class.pm index 7d2b004..9d49b69 100644 --- a/lib/DBIx/Class.pm +++ b/lib/DBIx/Class.pm @@ -29,6 +29,10 @@ $VERSION = '0.08109'; $VERSION = eval $VERSION; # numify for warning-free dev releases +# what version of sqlt do we require if deploy() without a ddl_dir is invoked +# when changing also adjust $sqlt_recommends in Makefile.PL +my $minimum_sqlt_version = '0.11002'; + sub MODIFY_CODE_ATTRIBUTES { my ($class,$code,@attrs) = @_; $class->mk_classdata('__attr_cache' => {}) @@ -44,6 +48,34 @@ sub _attr_cache { return $@ ? $cache : { %$cache, %$rest }; } +# 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 }; +} + + 1; =head1 NAME diff --git a/lib/DBIx/Class/Schema/Versioned.pm b/lib/DBIx/Class/Schema/Versioned.pm index 0874167..50cae7e 100644 --- a/lib/DBIx/Class/Schema/Versioned.pm +++ b/lib/DBIx/Class/Schema/Versioned.pm @@ -520,10 +520,8 @@ sub _create_db_to_schema_diff { return; } - eval 'require SQL::Translator "0.09003"'; - if ($@) { - $self->throw_exception("SQL::Translator 0.09003 required"); - } + $self->throw_exception($self->_sqlt_version_error) + if (not $self->_sqlt_version_ok); 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 ae7cb85..d7f1e9e 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -2282,9 +2282,8 @@ sub create_ddl_dir { %{$sqltargs || {}} }; - $self->throw_exception(q{Can't create a ddl file without SQL::Translator 0.09003: '} - . $self->_check_sqlt_message . q{'}) - if !$self->_check_sqlt_version; + $self->throw_exception("Can't create a ddl file without SQL::Translator: " . $self->_sqlt_version_error) + if !$self->_sqlt_version_ok; my $sqlt = SQL::Translator->new( $sqltargs ); @@ -2426,9 +2425,8 @@ sub deployment_statements { return join('', @rows); } - $self->throw_exception(q{Can't deploy without SQL::Translator 0.09003: '} - . $self->_check_sqlt_message . q{'}) - if !$self->_check_sqlt_version; + $self->throw_exception("Can't deploy without either SQL::Translator or a ddl_dir: " . $self->_sqlt_version_error ) + if !$self->_sqlt_version_ok; # sources needs to be a parser arg, but for simplicty allow at top level # coming in @@ -2515,21 +2513,6 @@ sub build_datetime_parser { return $type; } -{ - my $_check_sqlt_version; # private - my $_check_sqlt_message; # private - sub _check_sqlt_version { - return $_check_sqlt_version if defined $_check_sqlt_version; - eval 'use SQL::Translator "0.09003"'; - $_check_sqlt_message = $@ || ''; - $_check_sqlt_version = !$@; - } - - sub _check_sqlt_message { - _check_sqlt_version if !defined $_check_sqlt_message; - $_check_sqlt_message; - } -} =head2 is_replicating diff --git a/t/86sqlt.t b/t/86sqlt.t index 65f2dc8..1962431 100644 --- a/t/86sqlt.t +++ b/t/86sqlt.t @@ -5,8 +5,12 @@ use Test::More; use lib qw(t/lib); use DBICTest; -eval "use SQL::Translator"; -plan skip_all => 'SQL::Translator required' if $@; +BEGIN { + require DBIx::Class; + plan skip_all => + 'Test needs SQL::Translator ' . DBIx::Class->_sqlt_minimum_version + if not DBIx::Class->_sqlt_version_ok; +} my $schema = DBICTest->init_schema (no_deploy => 1); diff --git a/t/94versioning.t b/t/94versioning.t index d62f117..9ea6762 100644 --- a/t/94versioning.t +++ b/t/94versioning.t @@ -1,4 +1,5 @@ #!/usr/bin/perl + use strict; use warnings; use Test::More; @@ -15,11 +16,10 @@ BEGIN { plan skip_all => 'Set $ENV{DBICTEST_MYSQL_DSN}, _USER and _PASS to run this test' unless ($dsn); - - eval "use DBD::mysql; use SQL::Translator 0.09003;"; - plan $@ - ? ( skip_all => 'needs DBD::mysql and SQL::Translator 0.09003 for testing' ) - : ( tests => 22 ); + require DBIx::Class; + plan skip_all => + 'Test needs SQL::Translator ' . DBIx::Class->_sqlt_minimum_version + if not DBIx::Class->_sqlt_version_ok; } my $version_table_name = 'dbix_class_schema_versions'; @@ -182,3 +182,5 @@ TODO: { unless ($ENV{DBICTEST_KEEP_VERSIONING_DDL}) { unlink $_ for (values %$fn); } + +done_testing; diff --git a/t/99dbic_sqlt_parser.t b/t/99dbic_sqlt_parser.t index 5bbd302..6f3a3e2 100644 --- a/t/99dbic_sqlt_parser.t +++ b/t/99dbic_sqlt_parser.t @@ -5,12 +5,11 @@ use Test::More; use lib qw(t/lib); use DBICTest; - BEGIN { - eval "use SQL::Translator 0.09003;"; - if ($@) { - plan skip_all => 'needs SQL::Translator 0.09003 for testing'; - } + require DBIx::Class; + plan skip_all => + 'Test needs SQL::Translator ' . DBIx::Class->_sqlt_minimum_version + if not DBIx::Class->_sqlt_version_ok; } my $schema = DBICTest->init_schema(); @@ -23,8 +22,6 @@ my @sources = grep $schema->sources ; -plan tests => ( @sources * 3); - { my $sqlt_schema = create_schema({ schema => $schema, args => { parser_args => { } } }); @@ -65,6 +62,8 @@ plan tests => ( @sources * 3); } } +done_testing; + sub create_schema { my $args = shift;