From: Rafael Kitover Date: Wed, 3 Aug 2011 03:43:06 +0000 (-0400) Subject: remove loader args from connect_info X-Git-Tag: v0.53~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Model-DBIC-Schema.git;a=commitdiff_plain;h=7dd1b1e91847ae3d4b9f16acde7b5e4ca66fbb80 remove loader args from connect_info 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. --- diff --git a/Changes b/Changes index 64aed1d..c0dc937 100644 --- 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) diff --git a/lib/Catalyst/Helper/Model/DBIC/Schema.pm b/lib/Catalyst/Helper/Model/DBIC/Schema.pm index 472ef90..f1a6ebe 100644 --- a/lib/Catalyst/Helper/Model/DBIC/Schema.pm +++ b/lib/Catalyst/Helper/Model/DBIC/Schema.pm @@ -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; } } diff --git a/t/08helper.t b/t/08helper.t index 290553a..0c8afd3 100644 --- a/t/08helper.t +++ b/t/08helper.t @@ -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 {