From: Peter Rabbitson Date: Fri, 19 Mar 2010 17:39:02 +0000 (+0000) Subject: Fix UTF8Column out of order loading warning X-Git-Tag: v0.08121~52 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=72ae8e408a95ca2a9165a2dc1ae7952b5f51463f;p=dbsrgits%2FDBIx-Class.git Fix UTF8Column out of order loading warning --- diff --git a/Changes b/Changes index 2bf9cdf..a7b7337 100644 --- a/Changes +++ b/Changes @@ -24,6 +24,7 @@ Revision history for DBIx::Class - Fix update_all and delete_all to be wrapped in a transaction - Support add_columns('+colname' => { ... }) to augment column definitions. + - Fix spurious warnings on multiple UTF8Columns component loads - Unicode support documentation in Cookbook and UTF8Columns 0.08120 2010-02-24 08:58:00 (UTC) diff --git a/lib/DBIx/Class/Componentised.pm b/lib/DBIx/Class/Componentised.pm index 5a59238..fb0bd28 100644 --- a/lib/DBIx/Class/Componentised.pm +++ b/lib/DBIx/Class/Componentised.pm @@ -14,18 +14,23 @@ sub inject_base { my $target = shift; my @present_components = (@{mro::get_linear_isa ($target)||[]}); + shift @present_components; # don't need to interrogate myself no strict 'refs'; for my $comp (reverse @_) { - if ($comp->isa ('DBIx::Class::UTF8Columns') ) { + # if we are trying add a UTF8Columns component *for the first time* + if ($comp->isa ('DBIx::Class::UTF8Columns') && ! $target->isa ('DBIx::Class::UTF8Columns') ) { require B; my @broken; for (@present_components) { + last if $_ eq 'DBIx::Class::Row'; # don't care about anything further down the chain + my $cref = $_->can ('store_column') or next; - push @broken, $_ if B::svref_2object($cref)->STASH->NAME ne 'DBIx::Class::Row'; + + push @broken, $_ if B::svref_2object($cref)->STASH->NAME eq $_; } carp "Incorrect loading order of $comp by ${target} will affect other components overriding store_column (" diff --git a/t/85utf8.t b/t/85utf8.t index 9f1ab0f..5ea1a60 100644 --- a/t/85utf8.t +++ b/t/85utf8.t @@ -6,22 +6,52 @@ use Test::Warn; use lib qw(t/lib); use DBICTest; -warning_like ( - sub { - package A::Comp; - use base 'DBIx::Class'; - sub store_column { shift->next::method (@_) }; - 1; +{ + package A::Comp; + use base 'DBIx::Class'; + sub store_column { shift->next::method (@_) }; + 1; +} + +{ + package A::SubComp; + use base 'A::Comp'; + 1; +} +warnings_like ( + sub { package A::Test; use base 'DBIx::Class::Core'; - __PACKAGE__->load_components(qw(UTF8Columns +A::Comp)); + __PACKAGE__->load_components(qw(UTF8Columns +A::SubComp +A::Comp)); 1; }, - qr/Incorrect loading order of DBIx::Class::UTF8Columns.+affect other components overriding store_column \(A::Comp\)/, + [qr/Incorrect loading order of DBIx::Class::UTF8Columns.+affect other components overriding store_column \(A::Comp\)/], 'incorrect order warning issued', ); +warnings_are ( + sub { + package A::Test2; + use base 'DBIx::Class::Core'; + __PACKAGE__->load_components(qw(Core +A::Comp Ordered UTF8Columns)); + __PACKAGE__->load_components(qw(Ordered +A::Comp Row UTF8Columns Core)); + 1; + }, + [], + 'no spurious warnings issued', +); + +my $test2_mro; +my $idx = 0; +for (@{mro::get_linear_isa ('A::Test2')} ) { + $test2_mro->{$_} = $idx++; +} + +cmp_ok ($test2_mro->{'A::Comp'}, '<', $test2_mro->{'DBIx::Class::UTF8Columns'}, 'mro of Test2 correct (A::Comp before UTF8Col)' ); +cmp_ok ($test2_mro->{'DBIx::Class::UTF8Columns'}, '<', $test2_mro->{'DBIx::Class::Core'}, 'mro of Test2 correct (UTF8Col before Core)' ); +cmp_ok ($test2_mro->{'DBIx::Class::Core'}, '<', $test2_mro->{'DBIx::Class::Row'}, 'mro of Test2 correct (Core before Row)' ); + my $schema = DBICTest->init_schema(); DBICTest::Schema::CD->load_components('UTF8Columns'); DBICTest::Schema::CD->utf8_columns('title');