From: Jay Hannah Date: Thu, 31 Dec 2009 02:00:47 +0000 (+0000) Subject: Added skip_load_external() X-Git-Tag: 0.04999_13~14^2~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0ca61324edfaddb69ac51ddf6282f516fcc826db;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Added skip_load_external() --- diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index e73ee6c..c2772f7 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -30,6 +30,7 @@ __PACKAGE__->mk_group_ro_accessors('simple', qw/ components resultset_components skip_relationships + skip_load_external moniker_map inflect_singular inflect_plural @@ -83,6 +84,11 @@ L. Available constructor options ar Skip setting up relationships. The default is to attempt the loading of relationships. +=head2 skip_load_external + +Skip loading of other classes in @INC. The default is to merge all other classes +with the same name found in @INC into the schema file we are creating. + =head2 naming Static schemas (ones dumped to disk) will, by default, use the new-style 0.05XXX @@ -479,6 +485,8 @@ sub _find_class_in_inc { sub _load_external { my ($self, $class) = @_; + return if $self->{skip_load_external}; + # so that we don't load our own classes, under any circumstances local *INC = [ grep $_ ne $self->dump_directory, @INC ]; diff --git a/t/20invocations.t b/t/20invocations.t index 9d5ad65..474133d 100644 --- a/t/20invocations.t +++ b/t/20invocations.t @@ -103,14 +103,38 @@ my @invocations = ( [ $make_dbictest_db::dsn ], ); DBICTest::Schema::12->clone; - } + }, + 'skip_load_external_1' => 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( + 'DBICTest::Schema::13', + { really_erase_my_files => 1, naming => 'current' }, + [ $make_dbictest_db::dsn ], + ); + DBICTest::Schema::13->clone; + }, + 'skip_load_external_2' => 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( + 'DBICTest::Schema::14', + { really_erase_my_files => 1, naming => 'current', skip_load_external => 1 }, + [ $make_dbictest_db::dsn ], + ); + DBICTest::Schema::14->clone; + }, ); # 4 tests per k/v pair -plan tests => 2 * @invocations; +plan tests => 2 * @invocations + 2; # + 2 more manual ones below. while(@invocations >= 2) { my $style = shift @invocations; my $subref = shift @invocations; test_schema($style, &$subref); } + +is($DBICTest::Schema::13::Foo::skip_me, "bad mojo", "skip_load_external_1 skip_me"); +is($DBICTest::Schema::14::Foo::skip_me, undef, "skip_load_external_2 skip_me"); + diff --git a/t/lib/DBICTest/Schema/13/Foo.pm b/t/lib/DBICTest/Schema/13/Foo.pm new file mode 100644 index 0000000..ca5fc9b --- /dev/null +++ b/t/lib/DBICTest/Schema/13/Foo.pm @@ -0,0 +1,3 @@ +package DBICTest::Schema::13::Foo; +our $skip_me = "bad mojo"; +1; diff --git a/t/lib/DBICTest/Schema/14/Foo.pm b/t/lib/DBICTest/Schema/14/Foo.pm new file mode 100644 index 0000000..6f3bf73 --- /dev/null +++ b/t/lib/DBICTest/Schema/14/Foo.pm @@ -0,0 +1,3 @@ +package DBICTest::Schema::14::Foo; +our $skip_me = "bad mojo"; +1;