From: Brandon L. Black Date: Sun, 30 Jul 2006 00:39:45 +0000 (+0000) Subject: re-word options/code/pod to be less confusing wrt ResultSource vs source-definition... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=25fb14bdbf1f065e5bf0b373aeb9204de50598d0;p=dbsrgits%2FDBIx-Class-Historic.git re-word options/code/pod to be less confusing wrt ResultSource vs source-definition class/file --- diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index d81320e..8eeaed8 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -285,20 +285,20 @@ sub load_classes { =back This is an alternative to L above which assumes an alternative -layout for automatic class loading. It assumes that all ResultSource classes -to be loaded are underneath a sub-namespace of the schema called -"ResultSource", any corresponding ResultSet classes to be underneath a -sub-namespace of the schema called "ResultSet", and any corresponing -Result classes to be underneath a sub-namespace of the schema called "Result". +layout for automatic class loading. It assumes that all source-definition +classes to be loaded are underneath a sub-namespace of the schema called +"Source", any corresponding ResultSet classes to be underneath a sub-namespace +of the schema called "ResultSet", and any corresponing Result classes to be +underneath a sub-namespace of the schema called "Result". All of those sub-namespaces are configurable if you don't like the defaults, -via the options C, C, and +via the options C, C, and C, respectively. -If (and only if) you specify the option C, any found -ResultSource classes that have no manually-created corresponding ResultSet -class will have one created for them in memory in the C, -based on C. +If (and only if) you specify the option C, any found +source-definition classes that have no manually-created corresponding +ResultSet class will have their C set to +C. 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 @@ -306,27 +306,27 @@ it with a literal C<+>. Example: - # load My::Schema::ResultSource::CD, My::Schema::ResultSource::Artist, + # load My::Schema::Source::CD, My::Schema::Source::Artist, # My::Schema::ResultSet::CD, etc... My::Schema->load_namespaces; # Override everything... My::Schema->load_namespaces( - resultsource_namespace => 'RSources', + source_namespace => 'Srcs', resultset_namespace => 'RSets', result_namespace => 'Results', - default_resultset_base => 'RSetBase', + default_resultset_class => 'RSetBase', ); - # ... and if there is a My::Schema::RSources::Foo, but no matching - # My::Schema::RSets::Foo, then My::Schema::RSets::Foo will be created - # for you in memory, based on My::Schema::RSetBase + # ... and if there is a My::Schema::Srcs::Foo, but no matching + # My::Schema::RSets::Foo, then the Foo source will have its + # resultset_class set to My::Schema::RSetBase # Put things in other namespaces My::Schema->load_namespaces( - resultsource_namespace => '+Some::Place::RSources', + source_namespace => '+Some::Place::Sources', resultset_namespace => '+Another::Place::RSets', result_namespace => '+Crazy::Stuff::Results', - default_resultset_base => '+You::Never::Know::RSetBase', + default_resultset_class => '+You::Never::Know::RSetBase', ); @@ -335,19 +335,23 @@ Example: sub load_namespaces { my ($class, %args) = @_; - my $resultsource_namespace = $args{resultsource_namespace} || 'ResultSource'; - my $resultset_namespace = $args{resultset_namespace} || 'ResultSet'; - my $result_namespace = $args{result_namespace} || 'Result'; - my $default_resultset_base = $args{default_resultset_base}; + 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}; - foreach ($resultsource_namespace, $resultset_namespace, - $result_namespace, $default_resultset_base) { + $class->throw_exception('load_namespaces: unknown option(s): ' + . join(q{,}, map { qq{'$_'} } keys %args)) + if scalar keys %args; + + foreach ($source_namespace, $resultset_namespace, + $result_namespace, $default_resultset_class) { next if !$_; $_ = $class . '::' . $_ if !s/^\+//; } - my %sources = map { (substr($_, length "${resultsource_namespace}::"), $_) } - Module::Find::findallmod($resultsource_namespace); + my %sources = map { (substr($_, length "${source_namespace}::"), $_) } + Module::Find::findallmod($source_namespace); my %resultsets = map { (substr($_, length "${resultset_namespace}::"), $_) } Module::Find::findallmod($resultset_namespace); @@ -357,9 +361,9 @@ sub load_namespaces { my @to_register; { - no warnings qw/redefine/; + no warnings 'redefine'; local *Class::C3::reinitialize = sub { }; - use warnings qw/redefine/; + use warnings 'redefine'; foreach my $source (keys %sources) { my $source_class = $sources{$source}; @@ -368,21 +372,15 @@ sub load_namespaces { my $rs_class = delete $resultsets{$source}; my $rs_set = $source_class->resultset_class; - if(!$rs_set || $rs_set eq 'DBIx::Class::ResultSet') { + if($rs_set && $rs_set ne 'DBIx::Class::ResultSet') { if($rs_class) { - $class->ensure_class_loaded($rs_class); - $source_class->resultset_class($rs_class); - } - elsif($default_resultset_base) { - $class->ensure_class_loaded($default_resultset_base); - $rs_class = "$resultset_namespace\::$source"; - { no strict qw/refs/; @{"$rs_class\::ISA"} = ($default_resultset_base); } - $source_class->resultset_class($rs_class); + warn "We found ResultSet class '$rs_class' for '$source', but it seems " + . "that you had already set '$source' to use '$rs_set' instead"; } } - elsif($rs_set && $rs_class) { - warn "We found ResultSet class '$rs_class' for '$source', but it seems " - . "that you had already set '$source' to use '$rs_set' instead"; + elsif($rs_class ||= $default_resultset_class) { + $class->ensure_class_loaded($rs_class); + $source_class->resultset_class($rs_class); } my $r_class = delete $results{$source}; @@ -404,12 +402,12 @@ sub load_namespaces { foreach (sort keys %resultsets) { warn "load_namespaces found ResultSet class $_ with no " - . 'corresponding ResultSource'; + . 'corresponding source-definition class'; } foreach (sort keys %results) { warn "load_namespaces found Result class $_ with no " - . 'corresponding ResultSource'; + . 'corresponding source-definition class'; } Class::C3->reinitialize; diff --git a/t/39load_namespaces_four.t b/t/39load_namespaces_four.t index c8e7463..eccc78b 100644 --- a/t/39load_namespaces_four.t +++ b/t/39load_namespaces_four.t @@ -13,11 +13,11 @@ eval { local $SIG{__WARN__} = sub { $warnings .= shift }; package DBICNSTest; use base qw/DBIx::Class::Schema/; - __PACKAGE__->load_namespaces( default_resultset_base => 'RSBase' ); + __PACKAGE__->load_namespaces( default_resultset_class => 'RSBase' ); }; ok(!$@) or diag $@; -like($warnings, qr/load_namespaces found ResultSet class C with no corresponding ResultSource/); -like($warnings, qr/load_namespaces found Result class C with no corresponding ResultSource/); +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'); @@ -31,4 +31,4 @@ 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::ResultSource::B'); +is($resclass_b, 'DBICNSTest::Source::B'); diff --git a/t/39load_namespaces_one.t b/t/39load_namespaces_one.t index cf21fba..bd70370 100644 --- a/t/39load_namespaces_one.t +++ b/t/39load_namespaces_one.t @@ -16,8 +16,8 @@ eval { __PACKAGE__->load_namespaces; }; ok(!$@) or diag $@; -like($warnings, qr/load_namespaces found ResultSet class C with no corresponding ResultSource/); -like($warnings, qr/load_namespaces found Result class C with no corresponding ResultSource/); +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'); @@ -31,4 +31,4 @@ 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::ResultSource::B'); +is($resclass_b, 'DBICNSTest::Source::B'); diff --git a/t/39load_namespaces_three.t b/t/39load_namespaces_three.t index 4c6c464..531aa89 100644 --- a/t/39load_namespaces_three.t +++ b/t/39load_namespaces_three.t @@ -14,14 +14,14 @@ eval { package DBICNSTestOther; use base qw/DBIx::Class::Schema/; __PACKAGE__->load_namespaces( - resultsource_namespace => '+DBICNSTest::RSrc', + source_namespace => '+DBICNSTest::Src', resultset_namespace => '+DBICNSTest::RSet', result_namespace => '+DBICNSTest::Res' ); }; ok(!$@) or diag $@; -like($warnings, qr/load_namespaces found ResultSet class C with no corresponding ResultSource/); -like($warnings, qr/load_namespaces found Result class C with no corresponding ResultSource/); +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'); @@ -35,4 +35,4 @@ 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::RSrc::B'); +is($resclass_b, 'DBICNSTest::Src::B'); diff --git a/t/39load_namespaces_two.t b/t/39load_namespaces_two.t index a857654..8b98568 100644 --- a/t/39load_namespaces_two.t +++ b/t/39load_namespaces_two.t @@ -14,14 +14,14 @@ eval { package DBICNSTest; use base qw/DBIx::Class::Schema/; __PACKAGE__->load_namespaces( - resultsource_namespace => 'RSrc', + source_namespace => 'Src', resultset_namespace => 'RSet', result_namespace => 'Res' ); }; ok(!$@) or diag $@; -like($warnings, qr/load_namespaces found ResultSet class C with no corresponding ResultSource/); -like($warnings, qr/load_namespaces found Result class C with no corresponding ResultSource/); +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'); @@ -35,4 +35,4 @@ 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::RSrc::B'); +is($resclass_b, 'DBICNSTest::Src::B'); diff --git a/t/lib/DBICNSTest/ResultSource/A.pm b/t/lib/DBICNSTest/Source/A.pm similarity index 78% rename from t/lib/DBICNSTest/ResultSource/A.pm rename to t/lib/DBICNSTest/Source/A.pm index 6921ebf..a255935 100644 --- a/t/lib/DBICNSTest/ResultSource/A.pm +++ b/t/lib/DBICNSTest/Source/A.pm @@ -1,4 +1,4 @@ -package DBICNSTest::ResultSource::A; +package DBICNSTest::Source::A; use base qw/DBIx::Class/; __PACKAGE__->load_components(qw/PK::Auto Core/); __PACKAGE__->table('a'); diff --git a/t/lib/DBICNSTest/ResultSource/B.pm b/t/lib/DBICNSTest/Source/B.pm similarity index 78% rename from t/lib/DBICNSTest/ResultSource/B.pm rename to t/lib/DBICNSTest/Source/B.pm index fb5f309..2f7f284 100644 --- a/t/lib/DBICNSTest/ResultSource/B.pm +++ b/t/lib/DBICNSTest/Source/B.pm @@ -1,4 +1,4 @@ -package DBICNSTest::ResultSource::B; +package DBICNSTest::Source::B; use base qw/DBIx::Class/; __PACKAGE__->load_components(qw/PK::Auto Core/); __PACKAGE__->table('b'); diff --git a/t/lib/DBICNSTest/RSrc/A.pm b/t/lib/DBICNSTest/Src/A.pm similarity index 82% rename from t/lib/DBICNSTest/RSrc/A.pm rename to t/lib/DBICNSTest/Src/A.pm index 532017d..9fa1c05 100644 --- a/t/lib/DBICNSTest/RSrc/A.pm +++ b/t/lib/DBICNSTest/Src/A.pm @@ -1,4 +1,4 @@ -package DBICNSTest::RSrc::A; +package DBICNSTest::Src::A; use base qw/DBIx::Class/; __PACKAGE__->load_components(qw/PK::Auto Core/); __PACKAGE__->table('a'); diff --git a/t/lib/DBICNSTest/RSrc/B.pm b/t/lib/DBICNSTest/Src/B.pm similarity index 82% rename from t/lib/DBICNSTest/RSrc/B.pm rename to t/lib/DBICNSTest/Src/B.pm index 929d8c4..a836571 100644 --- a/t/lib/DBICNSTest/RSrc/B.pm +++ b/t/lib/DBICNSTest/Src/B.pm @@ -1,4 +1,4 @@ -package DBICNSTest::RSrc::B; +package DBICNSTest::Src::B; use base qw/DBIx::Class/; __PACKAGE__->load_components(qw/PK::Auto Core/); __PACKAGE__->table('b');