From: Rafael Kitover Date: Fri, 12 Mar 2010 03:02:38 +0000 (-0500) Subject: add config_file option X-Git-Tag: 0.06000~53 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=73099af426d1fbe30bba6542abeb91e7caf03feb;p=dbsrgits%2FDBIx-Class-Schema-Loader.git add config_file option --- diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index 5c395b9..dbfa47f 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -61,6 +61,7 @@ __PACKAGE__->mk_group_ro_accessors('simple', qw/ naming datetime_timezone datetime_locale + config_file /); @@ -418,6 +419,11 @@ columns with the DATE/DATETIME/TIMESTAMP data_types. Sets the locale attribute for L for all columns with the DATE/DATETIME/TIMESTAMP data_types. +=head1 config_file + +File in Perl format, which should return a HASH reference, from which to read +loader options. + =head1 METHODS None of these methods are intended for direct invocation by regular @@ -459,6 +465,18 @@ sub new { bless $self => $class; + if (my $config_file = $self->config_file) { + my $config_opts = do $config_file; + + croak "Error reading config from $config_file: $@" if $@; + + croak "Config file $config_file must be a hashref" unless ref($config_opts) eq 'HASH'; + + while (my ($k, $v) = each %$config_opts) { + $self->{$k} = $v unless exists $self->{$k}; + } + } + $self->_ensure_arrayref(qw/additional_classes additional_base_classes left_base_classes diff --git a/t/20invocations.t b/t/20invocations.t index 810c63c..b02402f 100644 --- a/t/20invocations.t +++ b/t/20invocations.t @@ -104,7 +104,7 @@ my @invocations = ( ); DBICTest::Schema::12->clone; }, - 'skip_load_external_1' => sub { + 'no_skip_load_external' => sub { # By default we should pull in t/lib/DBICTest/Schema/13/Foo.pm $skip_me since t/lib is in @INC use DBIx::Class::Schema::Loader; DBIx::Class::Schema::Loader::make_schema_at( @@ -114,7 +114,7 @@ my @invocations = ( ); DBICTest::Schema::13->clone; }, - 'skip_load_external_2' => sub { + 'skip_load_external' => sub { # When we explicitly skip_load_external t/lib/DBICTest/Schema/14/Foo.pm should be ignored use DBIx::Class::Schema::Loader; DBIx::Class::Schema::Loader::make_schema_at( diff --git a/t/23dumpmore.t b/t/23dumpmore.t index 1242d78..9aae2b1 100644 --- a/t/23dumpmore.t +++ b/t/23dumpmore.t @@ -1,11 +1,12 @@ use strict; use Test::More; -use lib qw(t/lib); use File::Path; use IPC::Open3; -use make_dbictest_db; use Data::Dumper::Concise; -require DBIx::Class::Schema::Loader; +use DBIx::Class::Schema::Loader (); +use File::Temp 'tempfile'; +use lib qw(t/lib); +use make_dbictest_db; my $DUMP_PATH = './t/_dump'; @@ -185,6 +186,32 @@ qr/package DBICTest::Schema::14::Foo;\nour \$skip_me = "bad mojo";\n1;/ rmtree($DUMP_PATH, 1, 1); +# test config_file + +my ($fh, $config_file) = tempfile; + +print $fh <<'EOF'; +{ skip_relationships => 1 } +EOF +close $fh; + +do_dump_test( + classname => 'DBICTest::Schema::14', + options => { config_file => $config_file }, + error => '', + warnings => [ + qr/Dumping manual schema for DBICTest::Schema::14 to directory /, + qr/Schema dump completed/, + ], + neg_regexes => { + Foo => [ + qr/has_many/, + ], + }, +); + +unlink $config_file; + # test out the POD do_dump_test(