support for fully-qualified components in result_component_map and tests
Rafael Kitover [Fri, 4 Mar 2011 08:25:26 +0000 (03:25 -0500)]
lib/DBIx/Class/Schema/Loader/Base.pm
t/lib/DBIx/Class/TestComponentForMap.pm [new file with mode: 0644]
t/lib/TestComponentForMapFQN.pm [new file with mode: 0644]
t/lib/dbixcsl_common_tests.pm

index 2d9cc7d..83fa077 100644 (file)
@@ -1620,10 +1620,10 @@ sub _make_src_class {
     $self->_inject($table_class, @{$self->left_base_classes});
 
     my @components = @{ $self->components || [] };
-    foreach my $moniker (keys %{ $self->result_component_map || {} }) {
-        next unless $moniker eq $table_moniker;
-        push @components, @{ $self->result_component_map->{$moniker} };
-    }
+
+    push @components, @{ $self->result_component_map->{$table_moniker} }
+        if exists $self->result_component_map->{$table_moniker};
+
     $self->_dbic_stmt($table_class, 'load_components', @components) if @components;
 
     $self->_inject($table_class, @{$self->additional_base_classes});
@@ -1637,10 +1637,14 @@ sub _is_result_class_method {
     if (not $self->_result_class_methods) {
         my (@methods, %methods);
         my $base       = $self->result_base_class || 'DBIx::Class::Core';
-        my @components = map { /^\+/ ? substr($_,1) : "DBIx::Class::$_" } @{ $self->components || [] };
-        foreach my $moniker (keys %{ $self->result_component_map || {} }) {
-            next unless $moniker eq $table_moniker;
-            push @components, @{ $self->result_component_map->{$moniker} };
+
+        my @components = @{ $self->components || [] };
+
+        push @components, @{ $self->result_component_map->{$table_moniker} }
+            if exists $self->result_component_map->{$table_moniker};
+
+        for my $c (@components) {
+            $c = $c =~ /^\+/ ? substr($c,1) : "DBIx::Class::$c";
         }
 
         for my $class ($base, @components, $self->use_moose ? 'Moose::Object' : ()) {
diff --git a/t/lib/DBIx/Class/TestComponentForMap.pm b/t/lib/DBIx/Class/TestComponentForMap.pm
new file mode 100644 (file)
index 0000000..8b3f715
--- /dev/null
@@ -0,0 +1,5 @@
+package DBIx::Class::TestComponentForMap;
+
+sub dbix_class_testcomponentformap { 'dbix_class_testcomponentformap works' }
+
+1;
diff --git a/t/lib/TestComponentForMapFQN.pm b/t/lib/TestComponentForMapFQN.pm
new file mode 100644 (file)
index 0000000..a63f79a
--- /dev/null
@@ -0,0 +1,5 @@
+package TestComponentForMapFQN;
+
+sub testcomponentformap_fqn { 'TestComponentForMapFQN works' }
+
+1;
index 0fa1710..b610fb5 100644 (file)
@@ -102,7 +102,7 @@ sub run_tests {
     $num_rescans++ if $self->{vendor} eq 'Firebird';
 
     plan tests => @connect_info *
-        (188 + $num_rescans * $col_accessor_map_tests + $extra_count + ($self->{data_type_tests}{test_count} || 0));
+        (192 + $num_rescans * $col_accessor_map_tests + $extra_count + ($self->{data_type_tests}{test_count} || 0));
 
     foreach my $info_idx (0..$#connect_info) {
         my $info = $connect_info[$info_idx];
@@ -224,6 +224,7 @@ sub setup_schema {
         col_collision_map       => { '^(can)\z' => 'caught_collision_%s' },
         rel_collision_map       => { '^(set_primary_key)\z' => 'caught_rel_collision_%s' },
         col_accessor_map        => \&test_col_accessor_map,
+        result_component_map    => { LoaderTest2X => 'TestComponentForMap', LoaderTest1 => '+TestComponentForMapFQN' },
         %{ $self->{loader_options} || {} },
     );
 
@@ -431,8 +432,20 @@ sub test_schema {
             'Additional Component' );
     }
 
-    is ((try { $class1->testcomponent_fqn }), 'TestComponentFQN works',
-        'fully qualified component class');
+    is try { $class2->dbix_class_testcomponentformap }, 'dbix_class_testcomponentformap works',
+        'component from result_component_map';
+
+    isnt try { $class1->dbix_class_testcomponentformap }, 'dbix_class_testcomponentformap works',
+        'component from result_component_map not added to not mapped Result';
+
+    is try { $class1->testcomponent_fqn }, 'TestComponentFQN works',
+        'fully qualified component class';
+
+    is try { $class1->testcomponentformap_fqn }, 'TestComponentForMapFQN works',
+        'fully qualified component class from result_component_map';
+
+    isnt try { $class2->testcomponentformap_fqn }, 'TestComponentForMapFQN works',
+        'fully qualified component class from result_component_map not added to not mapped Result';
 
     SKIP: {
         can_ok( $class1, 'loader_test1_classmeth' )