[Bast-commits] r9029 - in DBIx-Class/0.08/trunk: . lib/DBIx/Class t

ribasushi at dev.catalyst.perl.org ribasushi at dev.catalyst.perl.org
Fri Mar 19 17:39:02 GMT 2010


Author: ribasushi
Date: 2010-03-19 17:39:02 +0000 (Fri, 19 Mar 2010)
New Revision: 9029

Modified:
   DBIx-Class/0.08/trunk/Changes
   DBIx-Class/0.08/trunk/lib/DBIx/Class/Componentised.pm
   DBIx-Class/0.08/trunk/t/85utf8.t
Log:
Fix UTF8Column out of order loading warning

Modified: DBIx-Class/0.08/trunk/Changes
===================================================================
--- DBIx-Class/0.08/trunk/Changes	2010-03-19 15:03:41 UTC (rev 9028)
+++ DBIx-Class/0.08/trunk/Changes	2010-03-19 17:39:02 UTC (rev 9029)
@@ -24,6 +24,7 @@
         - 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)

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Componentised.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Componentised.pm	2010-03-19 15:03:41 UTC (rev 9028)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Componentised.pm	2010-03-19 17:39:02 UTC (rev 9029)
@@ -14,18 +14,23 @@
   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 ("

Modified: DBIx-Class/0.08/trunk/t/85utf8.t
===================================================================
--- DBIx-Class/0.08/trunk/t/85utf8.t	2010-03-19 15:03:41 UTC (rev 9028)
+++ DBIx-Class/0.08/trunk/t/85utf8.t	2010-03-19 17:39:02 UTC (rev 9029)
@@ -6,22 +6,52 @@
 use lib qw(t/lib);
 use DBICTest;
 
-warning_like (
+{
+  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::Comp;
-    use base 'DBIx::Class';
-    sub store_column { shift->next::method (@_) };
-    1;
-
     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');




More information about the Bast-commits mailing list