[Catalyst-commits] r10278 - in trunk/Catalyst-Model-DBIC-Schema:
lib/Catalyst/Helper/Model/DBIC t
caelum at dev.catalyst.perl.org
caelum at dev.catalyst.perl.org
Mon May 25 15:10:06 GMT 2009
Author: caelum
Date: 2009-05-25 15:10:06 +0000 (Mon, 25 May 2009)
New Revision: 10278
Modified:
trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Helper/Model/DBIC/Schema.pm
trunk/Catalyst-Model-DBIC-Schema/t/08helper.t
Log:
dbic helper - minor fixes for simple value detection
Modified: trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Helper/Model/DBIC/Schema.pm
===================================================================
--- trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Helper/Model/DBIC/Schema.pm 2009-05-24 22:30:47 UTC (rev 10277)
+++ trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Helper/Model/DBIC/Schema.pm 2009-05-25 15:10:06 UTC (rev 10278)
@@ -13,6 +13,7 @@
use Catalyst::Model::DBIC::Schema::Types 'CreateOption';
use Moose::Autobox;
use List::MoreUtils 'firstidx';
+use Scalar::Util 'looks_like_number';
use namespace::clean -except => 'meta';
@@ -227,7 +228,7 @@
while (my ($key, $val) = each %loader_args) {
next if $key =~ /^(?:components|constraint|exclude)\z/;
- $loader_args{$key} = eval $val;
+ $loader_args{$key} = $self->_eval($val);
die "syntax error for loader args key '$key' with value '$val': $@"
if $@;
}
@@ -328,7 +329,7 @@
for (@connect_info) {
if (/^\s*{.*}\s*\z/) {
- my $hash = eval $_;
+ my $hash = $self->_eval($_);
die "Syntax errorr in connect_info hash: $_: $@" if $@;
my %hash = %$hash;
@@ -410,7 +411,7 @@
for (@connect_info) {
if (/^\s*{.*}\s*\z/) {
- my $hash = eval $_;
+ my $hash = $self->_eval($_);
die "Syntax errorr in connect_info hash: $_: $@" if $@;
%connect_info = (%connect_info, %$hash);
@@ -423,7 +424,7 @@
if ($key =~ /^(?:quote_char|name_sep|limit_dialect)\z/) {
$connect_info{$key} = $val;
} else {
- $connect_info{$key} = eval $val;
+ $connect_info{$key} = $self->_eval($val);
}
die "syntax error for connect_info key '$key' with value '$val': $@"
@@ -449,6 +450,16 @@
$val;
}
+sub _eval {
+ my ($self, $code) = @_;
+
+ return $code if looks_like_number $code;
+
+ return $code if $code =~ m{^[\w;:/]*\z};
+
+ return eval "{no strict; $code}";
+}
+
sub _gen_dynamic_schema {
my $self = shift;
Modified: trunk/Catalyst-Model-DBIC-Schema/t/08helper.t
===================================================================
--- trunk/Catalyst-Model-DBIC-Schema/t/08helper.t 2009-05-24 22:30:47 UTC (rev 10277)
+++ trunk/Catalyst-Model-DBIC-Schema/t/08helper.t 2009-05-25 15:10:06 UTC (rev 10278)
@@ -4,7 +4,7 @@
use FindBin '$Bin';
use lib "$Bin/lib";
-use Test::More tests => 37;
+use Test::More tests => 38;
use Test::Exception;
use Catalyst::Helper::Model::DBIC::Schema;
use Catalyst::Helper;
@@ -80,6 +80,10 @@
is $i->loader_args->{exclude}, qr/^(foo|bar)$/,
'exclude loader arg';
+$i = instance(args => [$static, q{db_schema=foo;bar::baz/quux}]);
+is $i->loader_args->{db_schema}, q{foo;bar::baz/quux},
+ 'simple value loader arg';
+
$i = instance(args => [
$static, 'components=TimeStamp', $sqlite, $on_connect_do,
$quote_char, $name_sep
More information about the Catalyst-commits
mailing list