From: Jason M. Mills Date: Tue, 24 Mar 2009 07:49:54 +0000 (+0000) Subject: Fixed _register_source to not produce 'register_extra_source' warnings X-Git-Tag: v0.08100~24 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=40da099038cb3197d825c5ea4b34baf12775e080;p=dbsrgits%2FDBIx-Class.git Fixed _register_source to not produce 'register_extra_source' warnings when "registering class" isa (or is a sub-class) source class. This is not exactly an elegant fix as I had to pass a hash key (as _to_register via $params) with the original source class instance; I was not able to determine inheritance via the result_source_instance (ResultSource::Table) object. --- diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index cf7267d..413fe78 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -1221,7 +1221,9 @@ calling: sub register_class { my ($self, $moniker, $to_register) = @_; - $self->register_source($moniker => $to_register->result_source_instance); + $self->register_source($moniker => $to_register->result_source_instance, { + _to_register => $to_register + }); } =head2 register_source @@ -1279,7 +1281,11 @@ sub _register_source { if ($source->result_class) { my %map = %{$self->class_mappings}; - if (exists $map{$source->result_class}) { + my $is_subof = $params->{_to_register} && UNIVERSAL::isa( + $params->{_to_register}, + $source->result_class + ); + if (exists $map{$source->result_class} && !$is_subof) { warn $source->result_class . ' already has a source, use register_extra_source for additional sources'; } $map{$source->result_class} = $moniker; diff --git a/t/39load_namespaces_rt41083.t b/t/39load_namespaces_rt41083.t index 7d8dc5c..e0620fe 100644 --- a/t/39load_namespaces_rt41083.t +++ b/t/39load_namespaces_rt41083.t @@ -32,7 +32,7 @@ eval { }; ok(!$@) or diag $@; ok(_chk_warning($warnings), 'expected no resultset complaint'); -ok(_chk_extra_sources_warning($warnings), 'expected no extra sources complaint'); +ok(_chk_extra_sources_warning($warnings), 'expected no extra sources complaint') or diag($warnings); undef $warnings; eval { @@ -47,5 +47,5 @@ eval { }; ok(!$@) or diag $@; ok(_chk_warning($warnings), 'expected no resultset complaint') or diag $warnings; -ok(_chk_extra_sources_warning($warnings), 'expected no extra sources complaint'); +ok(_chk_extra_sources_warning($warnings), 'expected no extra sources complaint') or diag($warnings); undef $warnings;