From: Brandon L. Black Date: Wed, 23 Aug 2006 18:59:32 +0000 (+0000) Subject: remove result_class stuff from load_namespaces, better to not do it than to do it... X-Git-Tag: v0.08010~43^2~22^2~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=46a05fd450f4848c6dc5f1302001571a79f4728e;p=dbsrgits%2FDBIx-Class.git remove result_class stuff from load_namespaces, better to not do it than to do it wrong --- diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index 0b92c11..3103d29 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -288,20 +288,18 @@ This is an alternative to L above which assumes an alternative layout for automatic class loading. It assumes that all source-definition classes are underneath a sub-namespace of the schema called C, any corresponding ResultSet classes are underneath a sub-namespace of the schema -called C, and any corresponding Result classes are underneath a -sub-namespace of the schema called C. +called C. -All of those sub-namespaces are configurable if you don't like the defaults, -via the options C, C, and -C, respectively. +Both of the sub-namespaces are configurable if you don't like the defaults, +via the options C and C. If (and only if) you specify the option C, any found source-definition classes for which we do not find a corresponding ResultSet class will have their C set to C. -C takes care of calling C and/or -C for you where neccessary if you didn't do it for yourself. +C takes care of calling C for you where +neccessary if you didn't do it for yourself. All of the namespace and classname options to this method are relative to the schema classname by default. To specify a fully-qualified name, prefix @@ -317,7 +315,6 @@ Examples: My::Schema->load_namespaces( source_namespace => 'Srcs', resultset_namespace => 'RSets', - result_namespace => 'Results', default_resultset_class => 'RSetBase', ); # In the above, if there is a My::Schema::Srcs::Foo, but no matching @@ -332,11 +329,12 @@ Examples: If you'd like to use multiple namespaces of each type, simply use an arrayref of namespaces for that option. In the case that the same source-definition -(or resultset, or result) class exists in multiple namespaces, the latter -entries in your list of namespaces will override earlier ones. +(or resultset) class exists in multiple namespaces, the latter entries in +your list of namespaces will override earlier ones. My::Schema->load_namespaces( - source_namespace => [ 'Sources_C', 'Sources_B', 'Sources_A' ], + # My::Schema::Sources_C::Foo takes precedence over My::Schema::Sources_B::Foo : + source_namespace => [ 'Sources_A', 'Sources_B', 'Sources_C' ], resultset_namespace => [ '+Some::Place::RSets', 'RSets' ], ); @@ -375,7 +373,6 @@ sub load_namespaces { my $source_namespace = delete $args{source_namespace} || 'Source'; my $resultset_namespace = delete $args{resultset_namespace} || 'ResultSet'; - my $result_namespace = delete $args{result_namespace} || 'Result'; my $default_resultset_class = delete $args{default_resultset_class}; $class->throw_exception('load_namespaces: unknown option(s): ' @@ -385,7 +382,7 @@ sub load_namespaces { $default_resultset_class = $class->_expand_relative_name($default_resultset_class); - for my $arg ($source_namespace, $resultset_namespace, $result_namespace) { + for my $arg ($source_namespace, $resultset_namespace) { $arg = [ $arg ] if !ref($arg) && $arg; $class->throw_exception('load_namespaces: namespace arguments must be ' @@ -397,7 +394,6 @@ sub load_namespaces { my %sources = $class->_map_namespaces(@$source_namespace); my %resultsets = $class->_map_namespaces(@$resultset_namespace); - my %results = $class->_map_namespaces(@$result_namespace); my @to_register; { @@ -423,19 +419,6 @@ sub load_namespaces { $source_class->resultset_class($rs_class); } - my $r_class = delete $results{$source}; - if($r_class) { - my $r_set = $source_class->result_class; - if(!$r_set || $r_set eq $sources{$source}) { - $class->ensure_class_loaded($r_class); - $source_class->result_class($r_class); - } - elsif($r_set ne $r_class) { - warn "We found Result class '$r_class' for '$source', but it seems " - . "that you had already set '$source' to use '$r_set' instead"; - } - } - push(@to_register, [ $source_class->source_name, $source_class ]); } } @@ -445,11 +428,6 @@ sub load_namespaces { . 'corresponding source-definition class'; } - foreach (sort keys %results) { - warn "load_namespaces found Result class $_ with no " - . 'corresponding source-definition class'; - } - Class::C3->reinitialize; $class->register_class(@$_) for (@to_register); diff --git a/t/39load_namespaces_1.t b/t/39load_namespaces_1.t index bd70370..8d2dec3 100644 --- a/t/39load_namespaces_1.t +++ b/t/39load_namespaces_1.t @@ -6,7 +6,7 @@ use Test::More; unshift(@INC, './t/lib'); -plan tests => 9; +plan tests => 6; my $warnings; eval { @@ -17,18 +17,13 @@ eval { }; ok(!$@) or diag $@; like($warnings, qr/load_namespaces found ResultSet class C with no corresponding source-definition class/); -like($warnings, qr/load_namespaces found Result class C with no corresponding source-definition class/); my $source_a = DBICNSTest->source('A'); isa_ok($source_a, 'DBIx::Class::ResultSource::Table'); my $rset_a = DBICNSTest->resultset('A'); isa_ok($rset_a, 'DBICNSTest::ResultSet::A'); -my $resclass_a = DBICNSTest->resultset('A')->result_class; -is($resclass_a, 'DBICNSTest::Result::A'); my $source_b = DBICNSTest->source('B'); isa_ok($source_b, 'DBIx::Class::ResultSource::Table'); my $rset_b = DBICNSTest->resultset('B'); isa_ok($rset_b, 'DBIx::Class::ResultSet'); -my $resclass_b = DBICNSTest->resultset('B')->result_class; -is($resclass_b, 'DBICNSTest::Source::B'); diff --git a/t/39load_namespaces_2.t b/t/39load_namespaces_2.t index 8b98568..7bcb7c9 100644 --- a/t/39load_namespaces_2.t +++ b/t/39load_namespaces_2.t @@ -6,7 +6,7 @@ use Test::More; unshift(@INC, './t/lib'); -plan tests => 9; +plan tests => 6; my $warnings; eval { @@ -16,23 +16,17 @@ eval { __PACKAGE__->load_namespaces( source_namespace => 'Src', resultset_namespace => 'RSet', - result_namespace => 'Res' ); }; ok(!$@) or diag $@; like($warnings, qr/load_namespaces found ResultSet class C with no corresponding source-definition class/); -like($warnings, qr/load_namespaces found Result class C with no corresponding source-definition class/); my $source_a = DBICNSTest->source('A'); isa_ok($source_a, 'DBIx::Class::ResultSource::Table'); my $rset_a = DBICNSTest->resultset('A'); isa_ok($rset_a, 'DBICNSTest::RSet::A'); -my $resclass_a = DBICNSTest->resultset('A')->result_class; -is($resclass_a, 'DBICNSTest::Res::A'); my $source_b = DBICNSTest->source('B'); isa_ok($source_b, 'DBIx::Class::ResultSource::Table'); my $rset_b = DBICNSTest->resultset('B'); isa_ok($rset_b, 'DBIx::Class::ResultSet'); -my $resclass_b = DBICNSTest->resultset('B')->result_class; -is($resclass_b, 'DBICNSTest::Src::B'); diff --git a/t/39load_namespaces_3.t b/t/39load_namespaces_3.t index b066d64..ae87bf8 100644 --- a/t/39load_namespaces_3.t +++ b/t/39load_namespaces_3.t @@ -6,7 +6,7 @@ use Test::More; unshift(@INC, './t/lib'); -plan tests => 10; +plan tests => 7; my $warnings; eval { @@ -16,26 +16,20 @@ eval { __PACKAGE__->load_namespaces( source_namespace => [ '+DBICNSTest::Src', '+DBICNSTest::OtherSrc' ], resultset_namespace => '+DBICNSTest::RSet', - result_namespace => '+DBICNSTest::Res' ); }; ok(!$@) or diag $@; like($warnings, qr/load_namespaces found ResultSet class C with no corresponding source-definition class/); -like($warnings, qr/load_namespaces found Result class C with no corresponding source-definition class/); my $source_a = DBICNSTestOther->source('A'); isa_ok($source_a, 'DBIx::Class::ResultSource::Table'); my $rset_a = DBICNSTestOther->resultset('A'); isa_ok($rset_a, 'DBICNSTest::RSet::A'); -my $resclass_a = DBICNSTestOther->resultset('A')->result_class; -is($resclass_a, 'DBICNSTest::Res::A'); my $source_b = DBICNSTestOther->source('B'); isa_ok($source_b, 'DBIx::Class::ResultSource::Table'); my $rset_b = DBICNSTestOther->resultset('B'); isa_ok($rset_b, 'DBIx::Class::ResultSet'); -my $resclass_b = DBICNSTestOther->resultset('B')->result_class; -is($resclass_b, 'DBICNSTest::Src::B'); my $source_d = DBICNSTestOther->source('D'); isa_ok($source_d, 'DBIx::Class::ResultSource::Table'); diff --git a/t/39load_namespaces_4.t b/t/39load_namespaces_4.t index eccc78b..d58a5b0 100644 --- a/t/39load_namespaces_4.t +++ b/t/39load_namespaces_4.t @@ -6,7 +6,7 @@ use Test::More; unshift(@INC, './t/lib'); -plan tests => 9; +plan tests => 6; my $warnings; eval { @@ -17,18 +17,13 @@ eval { }; ok(!$@) or diag $@; like($warnings, qr/load_namespaces found ResultSet class C with no corresponding source-definition class/); -like($warnings, qr/load_namespaces found Result class C with no corresponding source-definition class/); my $source_a = DBICNSTest->source('A'); isa_ok($source_a, 'DBIx::Class::ResultSource::Table'); my $rset_a = DBICNSTest->resultset('A'); isa_ok($rset_a, 'DBICNSTest::ResultSet::A'); -my $resclass_a = DBICNSTest->resultset('A')->result_class; -is($resclass_a, 'DBICNSTest::Result::A'); my $source_b = DBICNSTest->source('B'); isa_ok($source_b, 'DBIx::Class::ResultSource::Table'); my $rset_b = DBICNSTest->resultset('B'); isa_ok($rset_b, 'DBICNSTest::RSBase'); -my $resclass_b = DBICNSTest->resultset('B')->result_class; -is($resclass_b, 'DBICNSTest::Source::B'); diff --git a/t/lib/DBICNSTest/Res/A.pm b/t/lib/DBICNSTest/Res/A.pm deleted file mode 100644 index 06bec97..0000000 --- a/t/lib/DBICNSTest/Res/A.pm +++ /dev/null @@ -1,3 +0,0 @@ -package DBICTest::Res::A; -use base qw/DBIx::Class::Row/; -1; diff --git a/t/lib/DBICNSTest/Res/C.pm b/t/lib/DBICNSTest/Res/C.pm deleted file mode 100644 index ab32e7e..0000000 --- a/t/lib/DBICNSTest/Res/C.pm +++ /dev/null @@ -1,3 +0,0 @@ -package DBICTest::Res::C; -use base qw/DBIx::Class::Row/; -1; diff --git a/t/lib/DBICNSTest/Result/A.pm b/t/lib/DBICNSTest/Result/A.pm deleted file mode 100644 index 71c5209..0000000 --- a/t/lib/DBICNSTest/Result/A.pm +++ /dev/null @@ -1,3 +0,0 @@ -package DBICTest::Result::A; -use base qw/DBIx::Class::Row/; -1; diff --git a/t/lib/DBICNSTest/Result/C.pm b/t/lib/DBICNSTest/Result/C.pm deleted file mode 100644 index 428c19b..0000000 --- a/t/lib/DBICNSTest/Result/C.pm +++ /dev/null @@ -1,3 +0,0 @@ -package DBICTest::Result::C; -use base qw/DBIx::Class::Row/; -1;