From: Matt S Trout Date: Wed, 7 Dec 2005 01:38:50 +0000 (+0000) Subject: Componentised fixup from Vsevolod (Simon) Ilyushchenko X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e4c247399478922875e57b44a13403739164f5d6;p=dbsrgits%2FDBIx-Class-Historic.git Componentised fixup from Vsevolod (Simon) Ilyushchenko --- diff --git a/lib/DBIx/Class/Componentised.pm b/lib/DBIx/Class/Componentised.pm index a89f0e8..0b13100 100644 --- a/lib/DBIx/Class/Componentised.pm +++ b/lib/DBIx/Class/Componentised.pm @@ -6,7 +6,7 @@ sub inject_base { my ($class, $target, @to_inject) = @_; { no strict 'refs'; - unshift(@{"${target}::ISA"}, grep { $target ne $_ } @to_inject); + unshift(@{"${target}::ISA"}, grep { $target ne $_ && !$target->isa($_)} @to_inject); } my $table = { Class::C3::_dump_MRO_table }; eval "package $target; import Class::C3;" unless exists $table->{$target}; diff --git a/t/04dont_break_c3.t b/t/04dont_break_c3.t new file mode 100644 index 0000000..5869869 --- /dev/null +++ b/t/04dont_break_c3.t @@ -0,0 +1,33 @@ +#!/usr/bin/perl -w +#Simon Ilyushchenko, 12/05/05 +#Testing the case when we try to inject into @ISA a class that's already a parent of the target class. + +use strict; +use Test::More tests => 2; + +{ +package AAA; + +use base "DBIx::Class::Core"; + +package BBB; + +use base 'AAA'; + +#Injecting a direct parent. +__PACKAGE__->inject_base( __PACKAGE__, 'AAA' ); + + +package CCC; + +use base 'AAA'; + +#Injecting an indirect parent. +__PACKAGE__->inject_base( __PACKAGE__, 'DBIx::Class::Core' ); +} + +eval { Class::C3::calculateMRO('BBB'); }; +ok (! $@, "Correctly skipped injecting a direct parent of class BBB"); + +eval { Class::C3::calculateMRO('CCC'); }; +ok (! $@, "Correctly skipped injecting an indirect parent of class BBB");