[Catalyst-commits] r12461 - in Catalyst-Model-DBIC-Schema/trunk: . lib/Catalyst/Helper/Model/DBIC lib/Catalyst/Model/DBIC t

caelum at dev.catalyst.perl.org caelum at dev.catalyst.perl.org
Tue Dec 22 02:38:52 GMT 2009


Author: caelum
Date: 2009-12-22 02:38:52 +0000 (Tue, 22 Dec 2009)
New Revision: 12461

Modified:
   Catalyst-Model-DBIC-Schema/trunk/Changes
   Catalyst-Model-DBIC-Schema/trunk/Makefile.PL
   Catalyst-Model-DBIC-Schema/trunk/lib/Catalyst/Helper/Model/DBIC/Schema.pm
   Catalyst-Model-DBIC-Schema/trunk/lib/Catalyst/Model/DBIC/Schema.pm
   Catalyst-Model-DBIC-Schema/trunk/t/05testapp.t
Log:
support coderefs for loader options for helper

Modified: Catalyst-Model-DBIC-Schema/trunk/Changes
===================================================================
--- Catalyst-Model-DBIC-Schema/trunk/Changes	2009-12-22 01:14:52 UTC (rev 12460)
+++ Catalyst-Model-DBIC-Schema/trunk/Changes	2009-12-22 02:38:52 UTC (rev 12461)
@@ -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 at ozum.net)
 
 0.31  Sun Oct 18 18:50:00 BST 2009
         - update for copyright info

Modified: Catalyst-Model-DBIC-Schema/trunk/Makefile.PL
===================================================================
--- Catalyst-Model-DBIC-Schema/trunk/Makefile.PL	2009-12-22 01:14:52 UTC (rev 12460)
+++ Catalyst-Model-DBIC-Schema/trunk/Makefile.PL	2009-12-22 02:38:52 UTC (rev 12461)
@@ -14,7 +14,7 @@
 requires 'List::MoreUtils';
 requires 'Tie::IxHash';
 
-test_requires 'Test::More';
+test_requires 'Test::More' => '0.92';
 test_requires 'Test::Exception';
 
 feature 'Catalyst::Helper support',

Modified: Catalyst-Model-DBIC-Schema/trunk/lib/Catalyst/Helper/Model/DBIC/Schema.pm
===================================================================
--- Catalyst-Model-DBIC-Schema/trunk/lib/Catalyst/Helper/Model/DBIC/Schema.pm	2009-12-22 01:14:52 UTC (rev 12460)
+++ Catalyst-Model-DBIC-Schema/trunk/lib/Catalyst/Helper/Model/DBIC/Schema.pm	2009-12-22 02:38:52 UTC (rev 12461)
@@ -4,7 +4,7 @@
 use Moose;
 no warnings 'uninitialized';
 
-our $VERSION = '0.31';
+our $VERSION = '0.32';
 $VERSION = eval $VERSION;
 
 use Carp;
@@ -107,6 +107,14 @@
     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<DBIx::Class::Schema::Loader::Base> for a list of options
 
 Create a dynamic DBIx::Class::Schema::Loader-based Schema,
@@ -455,7 +463,7 @@
 sub _is_struct {
     my ($self, $val) = @_;
 
-    return $val =~ /^\s*[[{]/;
+    return $val =~ /^\s*(?:sub|[[{])/;
 }
 
 sub _quote {

Modified: Catalyst-Model-DBIC-Schema/trunk/lib/Catalyst/Model/DBIC/Schema.pm
===================================================================
--- Catalyst-Model-DBIC-Schema/trunk/lib/Catalyst/Model/DBIC/Schema.pm	2009-12-22 01:14:52 UTC (rev 12460)
+++ Catalyst-Model-DBIC-Schema/trunk/lib/Catalyst/Model/DBIC/Schema.pm	2009-12-22 02:38:52 UTC (rev 12461)
@@ -5,7 +5,7 @@
 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 @@
 
 osfameron: C<osfameron at cpan.org>
 
+Ozum Eldogan C<ozum at ozum.net>
+
 =head1 COPYRIGHT
 
 Copyright (c) 2006 - 2009

Modified: Catalyst-Model-DBIC-Schema/trunk/t/05testapp.t
===================================================================
--- Catalyst-Model-DBIC-Schema/trunk/t/05testapp.t	2009-12-22 01:14:52 UTC (rev 12460)
+++ Catalyst-Model-DBIC-Schema/trunk/t/05testapp.t	2009-12-22 02:38:52 UTC (rev 12461)
@@ -11,14 +11,13 @@
 
 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 @@
 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 @@
    }
 }
 
-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);
+}




More information about the Catalyst-commits mailing list