From: Alexander Hartmaier Date: Fri, 17 Dec 2010 14:57:36 +0000 (+0100) Subject: added RDBMS optional dependency groups for use by DBIC users + tests X-Git-Tag: v0.08125~14 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=be68095d16b02db81aa1c37dfd6f6595f19d1ac2;p=dbsrgits%2FDBIx-Class.git added RDBMS optional dependency groups for use by DBIC users + tests --- diff --git a/Changes b/Changes index 69f1e95..ea0978d 100644 --- a/Changes +++ b/Changes @@ -42,6 +42,8 @@ Revision history for DBIx::Class - Add forgotten attributes to Admin.pm * Misc + - Add extra option groups to DBIC::Optional::Depencencies, to aid + users in requesting the prerequisites for a particular RDBMS - Switch all serialization to use Storable::nfreeze for portable architecture independent ice - Fix the bogus META.yml dependency injection issue for good diff --git a/Makefile.PL b/Makefile.PL index 67fa6e4..74c67b1 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -89,8 +89,11 @@ my $reqs = { test_requires => { %$test_requires }, }; +my %reqs_for_group = %{DBIx::Class::Optional::Dependencies->req_group_list}; + +# exclude the rdbms_* groups which are for DBIC users my $opt_testdeps = { - map { %$_ } (values %{DBIx::Class::Optional::Dependencies->req_group_list}) + map { %{$reqs_for_group{$_}} } grep { !/^rdbms_/ } keys %reqs_for_group }; # require extra modules for testing if we're in a checkout diff --git a/lib/DBIx/Class/Optional/Dependencies.pm b/lib/DBIx/Class/Optional/Dependencies.pm index 37759b9..1f353a3 100644 --- a/lib/DBIx/Class/Optional/Dependencies.pm +++ b/lib/DBIx/Class/Optional/Dependencies.pm @@ -43,6 +43,32 @@ my $id_shortener = { 'Math::Base36' => '0.07', }; +my $rdbms_sqlite = { + 'DBD::SQLite' => '0', +}; +my $rdbms_pg = { + 'DBD::Pg' => '0', +}; +my $rdbms_mssql_odbc = { + 'DBD::ODBC' => '0', +}; +my $rdbms_mssql_sybase = { + 'DBD::Sybase' => '0', +}; +my $rdbms_mysql = { + 'DBD::mysql' => '0', +}; +my $rdbms_oracle = { + 'DBD::Oracle' => '0', + %$id_shortener, +}; +my $rdbms_ase = { + 'DBD::Sybase' => '0', +}; +my $rdbms_db2 = { + 'DBD::DB2' => '0', +}; + my $reqs = { dist => { #'Module::Install::Pod::Inherit' => '0.01', @@ -179,10 +205,95 @@ my $reqs = { }, }, + # this is just for completeness as SQLite + # is a core dep of DBIC for testing + rdbms_sqlite => { + req => { + %$rdbms_sqlite, + }, + pod => { + title => 'SQLite support', + desc => 'Modules required to connect to SQLite', + }, + }, + + rdbms_pg => { + req => { + %$rdbms_pg, + }, + pod => { + title => 'PostgreSQL support', + desc => 'Modules required to connect to PostgreSQL', + }, + }, + + rdbms_mssql_odbc => { + req => { + %$rdbms_mssql_odbc, + }, + pod => { + title => 'MSSQL support via DBD::ODBC', + desc => 'Modules required to connect to MSSQL via DBD::ODBC', + }, + }, + + rdbms_mssql_sybase => { + req => { + %$rdbms_mssql_sybase, + }, + pod => { + title => 'MSSQL support via DBD::Sybase', + desc => 'Modules required to connect to MSSQL support via DBD::Sybase', + }, + }, + + rdbms_mysql => { + req => { + %$rdbms_mysql, + }, + pod => { + title => 'MySQL support', + desc => 'Modules required to connect to MySQL', + }, + }, + + rdbms_oracle => { + req => { + %$rdbms_oracle, + }, + pod => { + title => 'Oracle support', + desc => 'Modules required to connect to Oracle', + }, + }, + + rdbms_ase => { + req => { + %$rdbms_ase, + }, + pod => { + title => 'Sybase ASE support', + desc => 'Modules required to connect to Sybase ASE', + }, + }, + + rdbms_db2 => { + req => { + %$rdbms_db2, + }, + pod => { + title => 'DB2 support', + desc => 'Modules required to connect to DB2', + }, + }, + +# the order does matter because the rdbms support group might require +# a different version that the test group test_rdbms_pg => { req => { $ENV{DBICTEST_PG_DSN} ? ( + %$rdbms_pg, 'Sys::SigAction' => '0', 'DBD::Pg' => '2.009002', ) : () @@ -193,7 +304,7 @@ my $reqs = { req => { $ENV{DBICTEST_MSSQL_ODBC_DSN} ? ( - 'DBD::ODBC' => '0', + %$rdbms_mssql_odbc, ) : () }, }, @@ -202,7 +313,7 @@ my $reqs = { req => { $ENV{DBICTEST_MSSQL_DSN} ? ( - 'DBD::Sybase' => '0', + %$rdbms_mssql_sybase, ) : () }, }, @@ -211,7 +322,7 @@ my $reqs = { req => { $ENV{DBICTEST_MYSQL_DSN} ? ( - 'DBD::mysql' => '0', + %$rdbms_mysql, ) : () }, }, @@ -220,7 +331,7 @@ my $reqs = { req => { $ENV{DBICTEST_ORA_DSN} ? ( - %$id_shortener, + %$rdbms_oracle, 'DateTime::Format::Oracle' => '0', 'DBD::Oracle' => '1.24', ) : () @@ -231,7 +342,8 @@ my $reqs = { req => { $ENV{DBICTEST_SYBASE_DSN} ? ( - 'DateTime::Format::Sybase' => 0, + %$rdbms_ase, + 'DateTime::Format::Sybase' => '0', ) : () }, }, @@ -240,7 +352,7 @@ my $reqs = { req => { $ENV{DBICTEST_DB2_DSN} ? ( - 'DBD::DB2' => 0, + %$rdbms_db2, ) : () }, }, @@ -391,7 +503,7 @@ Somewhere in your build-file (e.g. L's Makefile.PL): require $class; - my \$deploy_deps = $class->req_list_for ('deploy'); + my \$deploy_deps = $class->req_list_for('deploy'); for (keys %\$deploy_deps) { requires \$_ => \$deploy_deps->{\$_}; diff --git a/xt/optional_deps.t b/xt/optional_deps.t index 11ef4d1..66f6a65 100644 --- a/xt/optional_deps.t +++ b/xt/optional_deps.t @@ -3,6 +3,7 @@ use warnings; no warnings qw/once/; use Test::More; +use Test::Exception; use lib qw(t/lib); use Scalar::Util; # load before we break require() use Carp (); # Carp is not used in the test, but we want to have it loaded for proper %INC comparison @@ -15,6 +16,13 @@ ok (1); my $inc_before = [ keys %INC ]; ok ( (! grep { $_ =~ m|DBIx/Class| } @$inc_before ), 'Nothing DBIC related is yet loaded'); +# DBIx::Class::Optional::Dependencies queries $ENV at compile time +# to build the optional requirements +BEGIN { + $ENV{DBICTEST_PG_DSN} = '1'; + $ENV{DBICTEST_ORA_DSN} = undef; +} + use_ok 'DBIx::Class::Optional::Dependencies'; my $inc_after = [ keys %INC ]; @@ -84,4 +92,39 @@ is_deeply ( 'expected empty errorlist', ); +# test multiple times to find autovivification bugs +for (1..2) { + throws_ok { + DBIx::Class::Optional::Dependencies->req_list_for(); + } qr/\Qreq_list_for() expects a requirement group name/, + "req_list_for without groupname throws exception on run $_"; + + throws_ok { + DBIx::Class::Optional::Dependencies->req_list_for(''); + } qr/\Qreq_list_for() expects a requirement group name/, + "req_list_for with empty groupname throws exception on run $_"; + + throws_ok { + DBIx::Class::Optional::Dependencies->req_list_for('invalid_groupname'); + } qr/Requirement group 'invalid_groupname' does not exist/, + "req_list_for with invalid groupname throws exception on run $_"; +} + +is_deeply( + DBIx::Class::Optional::Dependencies->req_list_for('rdbms_pg'), + { + 'DBD::Pg' => '0', + }, 'optional dependencies for deploying to Postgres ok'); + +is_deeply( + DBIx::Class::Optional::Dependencies->req_list_for('test_rdbms_pg'), + { + 'Sys::SigAction' => '0', + 'DBD::Pg' => '2.009002', + }, 'optional dependencies for testing Postgres with ENV var ok'); + +is_deeply( + DBIx::Class::Optional::Dependencies->req_list_for('test_rdbms_oracle'), + {}, 'optional dependencies for testing Oracle without ENV var ok'); + done_testing;