From: Rafael Kitover Date: Sun, 7 Aug 2011 12:57:12 +0000 (-0400) Subject: opt deps for dbicdump config and test X-Git-Tag: 0.07011~53 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class-Schema-Loader.git;a=commitdiff_plain;h=0322c5b3875e401b1e9bfc207713d5eaff31e4a0 opt deps for dbicdump config and test Adds Config::Any to dbicdump_config group in ::Optional::Dependencies and Config::Any with Config::General to the test_dbicdump_config group. Adds t/60dbicdump_config.t test for using a config file with dbicdump. --- diff --git a/lib/DBIx/Class/Schema/Loader/Optional/Dependencies.pm b/lib/DBIx/Class/Schema/Loader/Optional/Dependencies.pm index 0a3ac61..5f47f79 100644 --- a/lib/DBIx/Class/Schema/Loader/Optional/Dependencies.pm +++ b/lib/DBIx/Class/Schema/Loader/Optional/Dependencies.pm @@ -14,21 +14,42 @@ use Carp; # Makefile.PL in $AUTHOR mode my $reqs = { - dist => { - #'Module::Install::Pod::Inherit' => '0.01', - }, - - use_moose => { - req => { - 'Moose' => '1.12', - 'MooseX::NonMoose' => '0.16', - 'namespace::autoclean' => '0.09', + dist => { + #'Module::Install::Pod::Inherit' => '0.01', }, - pod => { - title => 'use_moose', - desc => 'Modules required for the use_moose option', + + use_moose => { + req => { + 'Moose' => '1.12', + 'MooseX::NonMoose' => '0.16', + 'namespace::autoclean' => '0.09', + }, + pod => { + title => 'use_moose', + desc => 'Modules required for the use_moose option', + }, + }, + + dbicdump_config => { + req => { + 'Config::Any' => '0', + }, + pod => { + title => 'dbicdump config file', + desc => 'Modules required for using a config file with dbicdump', + }, + }, + + test_dbicdump_config => { + req => { + 'Config::Any' => '0', + 'Config::General' => '0', + }, + pod => { + title => 'dbicdump config file testing', + desc => 'Modules required for using testing using a config file with dbicdump', + }, }, - }, }; sub req_list_for { diff --git a/script/dbicdump b/script/dbicdump index c6fdf3a..cb97638 100644 --- a/script/dbicdump +++ b/script/dbicdump @@ -33,7 +33,7 @@ On Windows that would be: -o preserve_case=1 ^ MyApp::Schema dbi:mysql:database=foo user pass "{ quote_char => q{`} }" -Configuration Files must have schema_class and connect_info sections, +Configuration files must have schema_class and connect_info sections, an example of a general config file is as follows: schema_class MyApp::Schema @@ -51,6 +51,8 @@ an example of a general config file is as follows: components TimeStamp +Using a config file requires L installed. + =head1 DESCRIPTION Dbicdump generates a L schema using @@ -86,12 +88,10 @@ under the same terms as Perl itself. use strict; use warnings; use Getopt::Long; -use Config::Any; - use Pod::Usage; - -use DBIx::Class::Schema::Loader qw/ make_schema_at /; -require DBIx::Class::Schema::Loader::Base; +use DBIx::Class::Schema::Loader 'make_schema_at'; +use DBIx::Class::Schema::Loader::Base (); +use DBIx::Class::Schema::Loader::Optional::Dependencies (); my $loader_options; @@ -99,7 +99,13 @@ GetOptions( 'loader-option|o=s%' => \&handle_option ); $loader_options->{dump_directory} ||= '.'; if (@ARGV == 1) { + if (not DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for('dbicdump_config')) { + die sprintf "You must install the following CPAN modules to use a config file with dbicdump: %s.\n", + DBIx::Class::Schema::Loader::Optional::Dependencies->req_missing_for('dbicdump_config'); + } + my $configuration_file = shift @ARGV; + my $configurations = Config::Any->load_files( { use_ext => 1, diff --git a/t/60dbicdump_config.t b/t/60dbicdump_config.t new file mode 100644 index 0000000..12c5153 --- /dev/null +++ b/t/60dbicdump_config.t @@ -0,0 +1,62 @@ +#!perl + +use strict; +use warnings; + +use Test::More; +use File::Path qw/make_path rmtree/; +use DBIx::Class::Schema::Loader::Optional::Dependencies (); +use DBIx::Class::Schema::Loader::Utils 'slurp_file'; +use lib 't/lib'; +use make_dbictest_db (); +use dbixcsl_test_dir '$tdir'; + +BEGIN { + use DBIx::Class::Schema::Loader::Optional::Dependencies (); + plan skip_all => 'Tests needs ' . DBIx::Class::Schema::Loader::Optional::Dependencies->req_missing_for('test_dbicdump_config') + unless (DBIx::Class::Schema::Loader::Optional::Dependencies->req_ok_for('test_dbicdump_config')); +} + +plan tests => 2; + +my $config_dir = "$tdir/dbicdump_config"; +make_path $config_dir; +my $config_file = "$config_dir/my.conf"; + +my $dump_path = "$tdir/dbicdump_config_dump"; + +open my $fh, '>', $config_file + or die "Could not write to $config_file: $!"; + +print $fh <<"EOF"; +schema_class DBICTest::Schema + + + dsn $make_dbictest_db::dsn + + + + dump_directory $dump_path + components InflateColumn::DateTime + quiet 1 + +EOF + +close $fh; + +system $^X, 'script/dbicdump', $config_file; + +is $? >> 8, 0, + 'dbicdump executed successfully'; + +my $foo = slurp_file "$dump_path/DBICTest/Schema/Result/Foo.pm"; + +like $foo, qr/InflateColumn::DateTime/, + 'loader options read correctly from config_file'; + +done_testing; + +END { + rmtree($config_dir, 1, 1); + rmtree($dump_path, 1, 1); +}