From: Dagfinn Ilmari Mannsåker Date: Sat, 18 Apr 2009 18:38:44 +0000 (+0000) Subject: Don't warn when reregistering a source under the same name X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5d77957881710b33a6f3cd8c36014e6a92838763;p=dbsrgits%2FDBIx-Class-Historic.git Don't warn when reregistering a source under the same name --- diff --git a/lib/DBIx/Class.pm b/lib/DBIx/Class.pm index e18801a..5a64365 100644 --- a/lib/DBIx/Class.pm +++ b/lib/DBIx/Class.pm @@ -241,6 +241,8 @@ gphat: Cory G Watson groditi: Guillermo Roditi +ilmari: Dagfinn Ilmari MannsEker + jesper: Jesper Krogh jgoulah: John Goulah diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index 4254b1e..1c4dd0e 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -1279,7 +1279,8 @@ sub _register_source { if ($source->result_class) { my %map = %{$self->class_mappings}; - if (exists $map{$source->result_class}) { + if (exists $map{$source->result_class} + && $map{$source->result_class} ne $moniker) { warn $source->result_class . ' already has a source, use register_extra_source for additional sources'; } $map{$source->result_class} = $moniker; diff --git a/t/100extra_source.t b/t/100extra_source.t index 5c531fd..c5c19bb 100644 --- a/t/100extra_source.t +++ b/t/100extra_source.t @@ -12,7 +12,7 @@ use DBICTest; use base qw/DBIx::Class::ResultSource::Table/; } -plan tests => 3; +plan tests => 4; my $schema = DBICTest->init_schema(); my $artist_source = $schema->source('Artist'); @@ -36,6 +36,12 @@ local $SIG{__WARN__} = sub { $warn = shift }; } { + my $source = $schema->source('DBICTest::Artist'); + $schema->register_source($source->source_name, $source); + is($warn, '', "regregistering an existing source under the same name causes no errors"); +} + +{ my $new_source_name = 'Artist->preview(artist_preview)'; $schema->register_source( $new_source_name => $new_source );