[Bast-commits] r5298 - in DBIx-Class/0.08/trunk: lib/DBIx/Class
lib/DBIx/Class/ResultSourceProxy t/lib/DBICNSTest/Result
matthewt at dev.catalyst.perl.org
matthewt at dev.catalyst.perl.org
Fri Jan 9 03:28:44 GMT 2009
Author: matthewt
Date: 2009-01-09 03:28:44 +0000 (Fri, 09 Jan 2009)
New Revision: 5298
Modified:
DBIx-Class/0.08/trunk/lib/DBIx/Class/DB.pm
DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSourceProxy/Table.pm
DBIx-Class/0.08/trunk/lib/DBIx/Class/Schema.pm
DBIx-Class/0.08/trunk/t/lib/DBICNSTest/Result/B.pm
Log:
fixup source registration bugs where schema-specific things were being set on class' result_source_instance objects
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/DB.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/DB.pm 2009-01-09 01:55:53 UTC (rev 5297)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/DB.pm 2009-01-09 03:28:44 UTC (rev 5298)
@@ -152,27 +152,47 @@
__PACKAGE__->mk_classdata('_result_source_instance' => []);
+# Yep. this is horrific. Basically what's happening here is that
+# (with good reason) DBIx::Class::Schema copies the result source for
+# registration. Because we have a retarded setup order forced on us we need
+# to actually make our ->result_source_instance -be- the source used, and we
+# need to get the source name and schema into ourselves. So this makes it
+# happen.
+
+sub _maybe_attach_source_to_schema {
+ my ($class, $source) = @_;
+ if (my $meth = $class->can('schema_instance')) {
+ my $schema = $class->$meth;
+ $schema->register_class($class, $class);
+ my $new_source = $schema->source($class);
+ %$source = %$new_source;
+ $schema->source_registrations->{$class} = $source;
+ }
+}
+
sub result_source_instance {
my $class = shift;
$class = ref $class || $class;
- return $class->_result_source_instance([$_[0], $class]) if @_;
+ if (@_) {
+ my $source = $_[0];
+ $class->_result_source_instance([$source, $class]);
+ $class->_maybe_attach_source_to_schema($source);
+ return $source;
+ }
my($source, $result_class) = @{$class->_result_source_instance};
return unless Scalar::Util::blessed($source);
if ($result_class ne $class) { # new class
# Give this new class it's own source and register it.
-
$source = $source->new({
%$source,
source_name => $class,
result_class => $class
} );
$class->_result_source_instance([$source, $class]);
- if (my $coderef = $class->can('schema_instance')) {
- $coderef->($class)->register_class($class, $class);
- }
+ $class->_maybe_attach_source_to_schema($source);
}
return $source;
}
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSourceProxy/Table.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSourceProxy/Table.pm 2009-01-09 01:55:53 UTC (rev 5297)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/ResultSourceProxy/Table.pm 2009-01-09 03:28:44 UTC (rev 5298)
@@ -40,11 +40,6 @@
$class->result_source_instance($table);
- if ($class->can('schema_instance') && $class->schema_instance) {
- $class =~ m/([^:]+)$/;
- $class->schema_instance->register_class($class, $class);
- }
-
return $table;
}
@@ -95,10 +90,6 @@
$class->result_source_instance($table);
- if ($class->can('schema_instance')) {
- $class =~ m/([^:]+)$/;
- $class->schema_instance->register_class($class, $class);
- }
return $class->result_source_instance->name;
}
Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Schema.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Schema.pm 2009-01-09 01:55:53 UTC (rev 5297)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Schema.pm 2009-01-09 03:28:44 UTC (rev 5298)
@@ -211,7 +211,6 @@
foreach my $result (keys %results) {
my $result_class = $results{$result};
$class->ensure_class_loaded($result_class);
- $result_class->source_name($result) unless $result_class->source_name;
my $rs_class = delete $resultsets{$result};
my $rs_set = $result_class->resultset_class;
@@ -226,7 +225,9 @@
$result_class->resultset_class($rs_class);
}
- push(@to_register, [ $result_class->source_name, $result_class ]);
+ my $source_name = $result_class->source_name || $result;
+
+ push(@to_register, [ $source_name, $result_class ]);
}
}
@@ -1228,7 +1229,7 @@
sub _register_source {
my ($self, $moniker, $source, $params) = @_;
- %$source = %{ $source->new( { %$source, source_name => $moniker }) };
+ $source = $source->new({ %$source, source_name => $moniker });
my %reg = %{$self->source_registrations};
$reg{$moniker} = $source;
Modified: DBIx-Class/0.08/trunk/t/lib/DBICNSTest/Result/B.pm
===================================================================
--- DBIx-Class/0.08/trunk/t/lib/DBICNSTest/Result/B.pm 2009-01-09 01:55:53 UTC (rev 5297)
+++ DBIx-Class/0.08/trunk/t/lib/DBICNSTest/Result/B.pm 2009-01-09 03:28:44 UTC (rev 5298)
@@ -1,5 +1,5 @@
package DBICNSTest::Result::B;
-use base qw/DBICNSTest::Result::A/;
+use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/PK::Auto Core/);
__PACKAGE__->table('b');
__PACKAGE__->add_columns('b');
More information about the Bast-commits
mailing list