remove loader args from connect_info
Rafael Kitover [Wed, 3 Aug 2011 03:43:06 +0000 (23:43 -0400)]
Improves the loader args reading code after connect_info to check the
keys against DBIx::Class::Schema::Loader::Base methods (loader options)
and splice them out of the connect_info information.

Changes
lib/Catalyst/Helper/Model/DBIC/Schema.pm
t/08helper.t

diff --git a/Changes b/Changes
index 64aed1d..c0dc937 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,8 @@
 Revision history for Perl extension Catalyst::Model::DBIC::Schema
 
+        - check loader args after connect_info against loader methods and remove
+          them from connect_info
+
 0.52  Thu Jul 28 22:07:38 UTC 2011
         - fix a bug in loader args reading after connect_info (skip structs)
 
index 472ef90..f1a6ebe 100644 (file)
@@ -311,19 +311,33 @@ sub _read_loader_args {
         $i += 2;
     }
 
-    while (defined $args->[$i]) {
-        $i++ while $self->_is_struct($args->[$i]);
+    my $have_loader = try {
+        Class::MOP::load_class('DBIx::Class::Schema::Loader::Base');
+        1;
+    };
 
-        last if not defined $args->[$i];
+    if ($have_loader) {
+        while (defined $args->[$i]) {
+            $i++ while $self->_is_struct($args->[$i]);
 
-        my ($key, $val) = split /=/, $args->[$i++], 2;
+            last if not defined $args->[$i];
 
-        if ($self->_is_struct($val)) {
-            $loader_args{$key} = $val;
-        } elsif ((my @vals = split /,/ => $val) > 1) {
-            $loader_args{$key} = \@vals;
-        } else {
-            $loader_args{$key} = $val;
+            my ($key, $val) = split /=/, $args->[$i], 2;
+
+            if (not DBIx::Class::Schema::Loader::Base->can($key)) {
+                $i++;
+                next;
+            }
+
+            if ($self->_is_struct($val)) {
+                $loader_args{$key} = $val;
+            } elsif ((my @vals = split /,/ => $val) > 1) {
+                $loader_args{$key} = \@vals;
+            } else {
+                $loader_args{$key} = $val;
+            }
+
+            splice @$args, $i, 1;
         }
     }
 
index 290553a..0c8afd3 100644 (file)
@@ -175,6 +175,9 @@ $i = instance(args => [
 is $i->loader_args->{db_schema}, 'myschema',
     'loader arg after connect_info';
 
+ok ((not exists $i->helper->{connect_info}{db_schema}),
+    'loader args removed from connect_info');
+
 done_testing;
 
 sub instance {