accept loader args after connect_info, release v0.51
Rafael Kitover [Wed, 27 Jul 2011 20:58:02 +0000 (16:58 -0400)]
Changes
lib/Catalyst/Helper/Model/DBIC/Schema.pm
lib/Catalyst/Model/DBIC/Schema.pm
t/08helper.t

diff --git a/Changes b/Changes
index c048478..e0c31d3 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,6 +1,8 @@
 Revision history for Perl extension Catalyst::Model::DBIC::Schema
 
+0.51  Wed Jul 27 20:57:47 UTC 2011
         - warn when helper finds no tables
+        - accept loader args after connect_info
 
 0.50  Fri May 20 22:45:07 UTC 2011
         - change repository link to the new git repo
index b947be4..5062ec1 100644 (file)
@@ -4,7 +4,7 @@ use namespace::autoclean;
 use Moose;
 no warnings 'uninitialized';
 
-our $VERSION = '0.50';
+our $VERSION = '0.51';
 $VERSION = eval $VERSION;
 
 use Carp;
@@ -300,6 +300,29 @@ sub _read_loader_args {
         }
     }
 
+    # Use args after connect_info as loader args as well, because people always
+    # get the order confused.
+    my $i = 1;
+    if ($args->[0] =~ /sqlite/i) {
+        $i++ if $args->[$i] eq '';
+        $i++ if $args->[$i] eq '';
+    }
+    else {
+        $i += 2;
+    }
+
+    while (defined $args->[$i]) {
+        my ($key, $val) = split /=/, $args->[$i++], 2;
+
+        if ($self->_is_struct($val)) {
+            $loader_args{$key} = $val;
+        } elsif ((my @vals = split /,/ => $val) > 1) {
+            $loader_args{$key} = \@vals;
+        } else {
+            $loader_args{$key} = $val;
+        }
+    }
+
     wantarray ? %loader_args : \%loader_args;
 }
 
index 3b2cfc2..12a3185 100644 (file)
@@ -5,7 +5,7 @@ use mro 'c3';
 extends 'Catalyst::Model';
 with 'CatalystX::Component::Traits';
 
-our $VERSION = '0.50';
+our $VERSION = '0.51';
 $VERSION = eval $VERSION;
 
 use namespace::autoclean;
index 27df355..290553a 100644 (file)
@@ -166,6 +166,15 @@ is $i->helper->{connect_info}{auto_savepoint}, 'q{1}',
 is $i->helper->{connect_info}{AutoCommit}, 'q{0}',
     'connect_info arg from extra hash as string';
 
+$i = instance(args => [
+    $static, 'components=TimeStamp', $sqlite, $on_connect_do,
+    $quote_char, $name_sep, 'auto_savepoint=1', 'AutoCommit=0',
+    'db_schema=myschema',
+]);
+
+is $i->loader_args->{db_schema}, 'myschema',
+    'loader arg after connect_info';
+
 done_testing;
 
 sub instance {