From: Rafael Kitover Date: Tue, 22 Dec 2009 02:38:52 +0000 (+0000) Subject: support coderefs for loader options for helper X-Git-Tag: v0.32~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ce9e19dc06c0e6df8cb3e32cca24b445b96b1031;p=catagits%2FCatalyst-Model-DBIC-Schema.git support coderefs for loader options for helper --- diff --git a/Changes b/Changes index e98e565..13cbafd 100644 --- a/Changes +++ b/Changes @@ -1,10 +1,13 @@ Revision history for Perl extension Catalyst::Model::DBIC::Schema +0.32 Mon Dec 21 21:33:53 EST 2009 - Move documentation on setting up authentication into its own section for clarity. - Other misc documentation enhancements to make the docs more clear about the important things to know. - Convert Authentication Plugin configuration example to new style. + - Support Coderefs in loader options for helper + (patch from Ozum Eldogan ozum@ozum.net) 0.31 Sun Oct 18 18:50:00 BST 2009 - update for copyright info diff --git a/Makefile.PL b/Makefile.PL index 2f4a846..e7e5c08 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -14,7 +14,7 @@ requires 'Carp::Clan'; requires 'List::MoreUtils'; requires 'Tie::IxHash'; -test_requires 'Test::More'; +test_requires 'Test::More' => '0.92'; test_requires 'Test::Exception'; feature 'Catalyst::Helper support', diff --git a/lib/Catalyst/Helper/Model/DBIC/Schema.pm b/lib/Catalyst/Helper/Model/DBIC/Schema.pm index 03f9741..4951027 100644 --- a/lib/Catalyst/Helper/Model/DBIC/Schema.pm +++ b/lib/Catalyst/Helper/Model/DBIC/Schema.pm @@ -4,7 +4,7 @@ use namespace::autoclean; use Moose; no warnings 'uninitialized'; -our $VERSION = '0.31'; +our $VERSION = '0.32'; $VERSION = eval $VERSION; use Carp; @@ -107,6 +107,14 @@ Same, but with extra Schema::Loader args (separate multiple values by commas): exclude='^(wibble|wobble)$' moniker_map='{ foo => "FOO" }' \ dbi:Pg:dbname=foodb myuname mypass +Coderefs are also supported: + + script/myapp_create.pl model CatalystModelName DBIC::Schema \ + MyApp::SchemaClass create=static \ + inflect_singular='sub { $_[0] =~ /\A(.+?)(_id)?\z/; $1 }' \ + moniker_map='sub { join(q{}, map ucfirst, split(/[\W_]+/, lc $_[0])); }' \ + dbi:mysql:foodb myuname mypass + See L for a list of options Create a dynamic DBIx::Class::Schema::Loader-based Schema, @@ -455,7 +463,7 @@ sub _parse_connect_info { sub _is_struct { my ($self, $val) = @_; - return $val =~ /^\s*[[{]/; + return $val =~ /^\s*(?:sub|[[{])/; } sub _quote { diff --git a/lib/Catalyst/Model/DBIC/Schema.pm b/lib/Catalyst/Model/DBIC/Schema.pm index c022003..81e4c4a 100644 --- a/lib/Catalyst/Model/DBIC/Schema.pm +++ b/lib/Catalyst/Model/DBIC/Schema.pm @@ -5,7 +5,7 @@ use mro 'c3'; extends 'Catalyst::Model'; with 'CatalystX::Component::Traits'; -our $VERSION = '0.31'; +our $VERSION = '0.32'; $VERSION = eval $VERSION; use namespace::autoclean; @@ -692,6 +692,8 @@ t0m: Tomas Doran C osfameron: C +Ozum Eldogan C + =head1 COPYRIGHT Copyright (c) 2006 - 2009 diff --git a/t/05testapp.t b/t/05testapp.t index 21f0e46..2b39662 100644 --- a/t/05testapp.t +++ b/t/05testapp.t @@ -11,14 +11,13 @@ plan skip_all => 'Enable this optional test with $ENV{C_M_DBIC_SCHEMA_TESTAPP}' my $test_params = [ [ 'TestSchema', 'DBIC::Schema', '' ], - [ 'TestSchemaDSN', 'DBIC::Schema', q{fakedsn fakeuser fakepass "{ AutoCommit => 1 }"} ], - [ 'TestSchemaDSN', 'DBIC::Schema', q{create=static traits=Caching moniker_map="{ roles => \"ROLE\" }" constraint="^users\z" dbi:SQLite:testdb.db} ], - [ 'TestSchemaDSN', 'DBIC::Schema', q{create=static traits=Caching moniker_map="{ roles => \"ROLE\" }" constraint="^users\z" dbi:SQLite:testdb.db "" "" on_connect_do="[\"select 1\", \"select 2\"]" quote_char="\""} ], - [ 'TestSchemaDSN', 'DBIC::Schema', q{create=static traits=Caching moniker_map="{ roles => \"ROLE\" }" dbi:SQLite:testdb.db on_connect_do="[\"select 1\", \"select 2\"]" quote_char="\""} ], + [ 'TestSchemaDSN', 'DBIC::Schema', qw/fakedsn fakeuser fakepass/, '{ AutoCommit => 1 }' ], + [ 'TestSchemaDSN', 'DBIC::Schema', 'create=static', 'traits=Caching', 'moniker_map={ roles => "ROLE" }', 'constraint=^users\z', 'dbi:SQLite:testdb.db' ], + [ 'TestSchemaDSN', 'DBIC::Schema', 'create=static', 'traits=Caching', 'moniker_map={ roles => "ROLE" }', 'constraint=^users\z', 'dbi:SQLite:testdb.db', '', '', 'on_connect_do=["select 1", "select 2"]', 'quote_char="' ], + [ 'TestSchemaDSN', 'DBIC::Schema', 'create=static', 'traits=Caching', 'moniker_map={ roles => "ROLE" }', 'dbi:SQLite:testdb.db', 'on_connect_do=["select 1", "select 2"]', 'quote_char="' ], + [ 'TestSchemaDSN', 'DBIC::Schema', 'create=static', 'traits=Caching', 'inflect_singular=sub { $_[0] =~ /\A(.+?)(_id)?\z/; $1 }', q{moniker_map=sub { return join('', map ucfirst, split(/[\W_]+/, lc $_[0])); }}, 'dbi:SQLite:testdb.db' ], ]; -plan tests => (2 * @$test_params + 3); - my $test_dir = $FindBin::Bin; my $blib_dir = File::Spec->catdir ($test_dir, '..', 'blib', 'lib'); my $cat_dir = File::Spec->catdir ($test_dir, 'TestApp'); @@ -52,17 +51,22 @@ EOF close $sql; foreach my $tparam (@$test_params) { - my ($model, $helper, $args) = @$tparam; - system("$^X -I$blib_dir $creator model $model $helper $model $args"); + my ($model, $helper, @args) = @$tparam; + + unlink for glob(File::Spec->catfile($schema_dir, 'Result', '*')); + + system($^X, "-I$blib_dir", $creator, 'model', $model, $helper, $model, @args); + my $model_path = File::Spec->catfile($model_dir, $model . '.pm'); ok( -f $model_path, "$model_path is a file" ); my $compile_rv = system("$^X -I$blib_dir -I$catlib_dir -c $model_path"); ok($compile_rv == 0, "perl -c $model_path"); - if ($args =~ /create=static/) { + if (grep /create=static/, @args) { my $glob = File::Spec->catfile($schema_dir, 'Result', '*'); my $tables =()= glob($glob); - if ($args =~ /constraint/) { + + if (grep /constraint/, @args) { is $tables, 1, 'constraint works'; } else { is $tables, 2, 'correct number of tables'; @@ -70,11 +74,15 @@ foreach my $tparam (@$test_params) { } } -chdir($test_dir); +done_testing; sub rm_rf { my $name = $File::Find::name; if(-d $name) { rmdir $name or die "Cannot rmdir $name: $!" } else { unlink $name or die "Cannot unlink $name: $!" } } -finddepth(\&rm_rf, $cat_dir); + +END { + chdir($test_dir); + finddepth(\&rm_rf, $cat_dir); +}