From: Robert Sedlacek Date: Sun, 16 Apr 2006 20:57:56 +0000 (+0000) Subject: inject_base filters out double entries X-Git-Tag: v0.06002~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d6fd708475c878947014304386173d7a8b9f4698;p=dbsrgits%2FDBIx-Class.git inject_base filters out double entries --- diff --git a/lib/DBIx/Class/Componentised.pm b/lib/DBIx/Class/Componentised.pm index a8a17c3..7e62354 100644 --- a/lib/DBIx/Class/Componentised.pm +++ b/lib/DBIx/Class/Componentised.pm @@ -10,7 +10,11 @@ sub inject_base { my ($class, $target, @to_inject) = @_; { no strict 'refs'; - unshift(@{"${target}::ISA"}, grep { $target ne $_ && !$target->isa($_)} @to_inject); + my %seen; + unshift( @{"${target}::ISA"}, + grep { !$seen{ $_ }++ && $target ne $_ && !$target->isa($_) } + @to_inject + ); } # Yes, this is hack. But it *does* work. Please don't submit tickets about diff --git a/t/05components.t b/t/05components.t index 57bebd5..fd0742f 100644 --- a/t/05components.t +++ b/t/05components.t @@ -7,8 +7,27 @@ use Test::More; use lib qw(t/lib); use DBICTest::ForeignComponent; -plan tests => 1; +plan tests => 2; # Tests if foreign component was loaded by calling foreign's method ok( DBICTest::ForeignComponent->foreign_test_method, 'foreign component' ); +# Test for inject_base to filter out duplicates +{ package DBICTest::_InjectBaseTest; + use base qw/ DBIx::Class /; +} +DBICTest::_InjectBaseTest->inject_base( 'DBICTest::_InjectBaseTest', qw/ + DBICTest::_InjectBaseTest::A + DBICTest::_InjectBaseTest::B + DBICTest::_InjectBaseTest::B + DBICTest::_InjectBaseTest::C +/); +is_deeply( \@DBICTest::_InjectBaseTest::ISA, + [qw/ + DBICTest::_InjectBaseTest::A + DBICTest::_InjectBaseTest::B + DBICTest::_InjectBaseTest::C + DBIx::Class + /], + 'inject_base filters duplicates' +);