From: Brandon L. Black Date: Tue, 5 Jun 2007 11:07:34 +0000 (+0000) Subject: Fixed up SQLT test/runtime deps X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=40dce2a5f0f24e152fe1773760904619804abb1f;p=dbsrgits%2FDBIx-Class-Historic.git Fixed up SQLT test/runtime deps --- diff --git a/Changes b/Changes index c572153..1443012 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,6 @@ Revision history for DBIx::Class + - Fixed up SQL::Translator test/runtime dependencies - Fixed t/60core.t in the absence of DateTime::Format::MySQL 0.07999_04 2007-06-01 14:04:00 diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 2556ce1..e1d50ef 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1231,8 +1231,9 @@ sub create_ddl_dir $version ||= $schema->VERSION || '1.x'; $sqltargs = { ( add_drop_table => 1 ), %{$sqltargs || {}} }; - eval "use SQL::Translator"; - $self->throw_exception("Can't create a ddl file without SQL::Translator: $@") if $@; + $self->throw_exception(q{Can't create a ddl file without SQL::Translator 0.08: '} + . $self->_check_sqlt_message . q{'}) + if !$self->_check_sqlt_version; my $sqlt = SQL::Translator->new({ # debug => 1, @@ -1271,12 +1272,7 @@ sub create_ddl_dir if($preversion) { - eval "use SQL::Translator::Diff"; - if($@) - { - warn("Can't diff versions without SQL::Translator::Diff: $@"); - next; - } + require SQL::Translator::Diff; my $prefilename = $schema->ddl_filename($db, $dir, $preversion); # print "Previous version $prefilename\n"; @@ -1385,25 +1381,23 @@ sub deployment_statements { return join('', @rows); } - eval "use SQL::Translator"; - if(!$@) - { - eval "use SQL::Translator::Parser::DBIx::Class;"; - $self->throw_exception($@) if $@; - eval "use SQL::Translator::Producer::${type};"; - $self->throw_exception($@) if $@; - - # sources needs to be a parser arg, but for simplicty allow at top level - # coming in - $sqltargs->{parser_args}{sources} = delete $sqltargs->{sources} - if exists $sqltargs->{sources}; - - my $tr = SQL::Translator->new(%$sqltargs); - SQL::Translator::Parser::DBIx::Class::parse( $tr, $schema ); - return "SQL::Translator::Producer::${type}"->can('produce')->($tr); - } + $self->throw_exception(q{Can't deploy without SQL::Translator 0.08: '} + . $self->_check_sqlt_message . q{'}) + if !$self->_check_sqlt_version; + + require SQL::Translator::Parser::DBIx::Class; + eval qq{use SQL::Translator::Producer::${type}}; + $self->throw_exception($@) if $@; + + # sources needs to be a parser arg, but for simplicty allow at top level + # coming in + $sqltargs->{parser_args}{sources} = delete $sqltargs->{sources} + if exists $sqltargs->{sources}; + + my $tr = SQL::Translator->new(%$sqltargs); + SQL::Translator::Parser::DBIx::Class::parse( $tr, $schema ); + return "SQL::Translator::Producer::${type}"->can('produce')->($tr); - $self->throw_exception("No SQL::Translator, and no Schema file found, aborting deploy"); return; } @@ -1459,6 +1453,22 @@ 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.08'; + $_check_sqlt_message = $@ ? $@ : ''; + $_check_sqlt_version = $@ ? 0 : 1; + } + + sub _check_sqlt_message { + _check_sqlt_version if !defined $_check_sqlt_message; + $_check_sqlt_message; + } +} + sub DESTROY { my $self = shift; return if !$self->_dbh; diff --git a/t/94versioning.t b/t/94versioning.t index 52bf415..697e5b2 100644 --- a/t/94versioning.t +++ b/t/94versioning.t @@ -5,9 +5,9 @@ use Test::More; use File::Spec; BEGIN { - eval "use DBD::SQLite; use SQL::Translator;"; + eval "use DBD::SQLite; use SQL::Translator 0.08;"; plan $@ - ? ( skip_all => 'needs DBD::SQLite and SQL::Translator for testing' ) + ? ( skip_all => 'needs DBD::SQLite and SQL::Translator 0.08 for testing' ) : ( tests => 6 ); }