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

caelum at dev.catalyst.perl.org caelum at dev.catalyst.perl.org
Sun May 17 23:20:52 GMT 2009


Author: caelum
Date: 2009-05-17 23:20:51 +0000 (Sun, 17 May 2009)
New Revision: 10192

Modified:
   trunk/Catalyst-Model-DBIC-Schema/Makefile.PL
   trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Helper/Model/DBIC/Schema.pm
   trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Model/DBIC/Schema.pm
   trunk/Catalyst-Model-DBIC-Schema/t/05testapp.t
Log:
dbic helper - make user/pass optional for sqlite, add a couple more tests

Modified: trunk/Catalyst-Model-DBIC-Schema/Makefile.PL
===================================================================
--- trunk/Catalyst-Model-DBIC-Schema/Makefile.PL	2009-05-17 21:45:11 UTC (rev 10191)
+++ trunk/Catalyst-Model-DBIC-Schema/Makefile.PL	2009-05-17 23:20:51 UTC (rev 10192)
@@ -14,7 +14,7 @@
 requires 'Carp::Clan';
 requires 'List::MoreUtils';
 
-test_requires 'Test::More';
+build_requires 'Test::More';
 
 feature 'Catalyst::Helper support',
     -default                      => 0,
@@ -23,10 +23,13 @@
     'DBIx::Class::Schema::Loader' => '0.04005';
 
 feature 'Caching support',
+    -default                      => 0,
     'DBIx::Class::Cursor::Cached' => 0;
 
 feature 'Replication support',
-    'MooseX::AttributeHelpers' => 0;
+    -default                   => 0,
+    'MooseX::AttributeHelpers' => 0,
+    'Hash::Merge'              => 0;
 
 if(-e 'MANIFEST.SKIP') {
     system("pod2text lib/Catalyst/Model/DBIC/Schema.pm > README");

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-17 21:45:11 UTC (rev 10191)
+++ trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Helper/Model/DBIC/Schema.pm	2009-05-17 23:20:51 UTC (rev 10192)
@@ -64,40 +64,58 @@
 existing Schemas, but required if you use either of the C<create=>
 options.
 
+username and password can be omitted for C<SQLite> dsns.
+
 Use of either of the C<create=> options requires L<DBIx::Class::Schema::Loader>.
 
 =head1 TYPICAL EXAMPLES
 
-  # Use DBIx::Class::Schema::Loader to create a static DBIx::Class::Schema,
-  #  and a Model which references it:
+Use DBIx::Class::Schema::Loader to create a static DBIx::Class::Schema,
+and a Model which references it:
+
   script/myapp_create.pl model CatalystModelName DBIC::Schema \
     MyApp::SchemaClass create=static dbi:mysql:foodb myuname mypass
 
-  # Same, with extra connect_info args
+Same, with extra connect_info args
+user and pass can be omitted for sqlite, since they are always empty
+
   script/myapp_create.pl model CatalystModelName DBIC::Schema \
-    MyApp::SchemaClass create=static dbi:SQLite:foo.db '' '' \
+    MyApp::SchemaClass create=static dbi:SQLite:foo.db \
     AutoCommit=1 cursor_class=DBIx::Class::Cursor::Cached \
-    on_connect_do='["select 1", "select 2"]'
+    on_connect_do='["select 1", "select 2"]' quote_char='"'
 
-  # Same, but with extra Schema::Loader args (separate multiple values by commas):
+B<ON WINDOWS COMMAND LINES QUOTING RULES ARE DIFFERENT>
+
+In C<cmd.exe> the above example would be:
+
   script/myapp_create.pl model CatalystModelName DBIC::Schema \
+    MyApp::SchemaClass create=static dbi:SQLite:foo.db \
+    AutoCommit=1 cursor_class=DBIx::Class::Cursor::Cached \
+    on_connect_do="[\"select 1\", \"select 2\"]" quote_char="\""
+
+Same, but with extra Schema::Loader args (separate multiple values by commas):
+
+  script/myapp_create.pl model CatalystModelName DBIC::Schema \
     MyApp::SchemaClass create=static db_schema=foodb components=Foo,Bar \
-    exclude='^wibble|wobble$' moniker_map='{ foo => "FFFFUUUU" }' \
+    exclude='^wibble|wobble$' moniker_map='{ foo => "FOO" }' \
     dbi:Pg:dbname=foodb myuname mypass
 
-  # See DBIx::Class::Schema::Loader::Base for list of options
+See L<DBIx::Class::Schema::Loader::Base> for a list of options
 
-  # Create a dynamic DBIx::Class::Schema::Loader-based Schema,
-  #  and a Model which references it:
+Create a dynamic DBIx::Class::Schema::Loader-based Schema,
+and a Model which references it (B<DEPRECATED>):
+
   script/myapp_create.pl model CatalystModelName DBIC::Schema \
     MyApp::SchemaClass create=dynamic dbi:mysql:foodb myuname mypass
 
-  # Reference an existing Schema of any kind, and provide some connection information for ->config:
+Reference an existing Schema of any kind, and provide some connection information for ->config:
+
   script/myapp_create.pl model CatalystModelName DBIC::Schema \
     MyApp::SchemaClass dbi:mysql:foodb myuname mypass
 
-  # Same, but don't supply connect information yet (you'll need to do this
-  #  in your app config, or [not recommended] in the schema itself).
+Same, but don't supply connect information yet (you'll need to do this
+in your app config, or [not recommended] in the schema itself).
+
   script/myapp_create.pl model ModelName DBIC::Schema My::SchemaClass
 
 =cut
@@ -262,7 +280,7 @@
 
     my @connect_info = @$connect_info;
 
-    my ($dsn, $user, $password) = splice @connect_info, 0, 3;
+    my ($dsn, $user, $password) = $self->_get_dsn_user_pass(\@connect_info);
 
     tie my %helper_connect_info, 'Tie::IxHash';
 
@@ -328,12 +346,28 @@
     return Data::Dumper->Dump([$data]);
 }
 
+sub _get_dsn_user_pass {
+    my ($self, $connect_info) = @_;
+
+    my $dsn = shift @$connect_info;
+    my ($user, $password);
+
+    if ($dsn =~ /sqlite/i) {
+        ($user, $password) = ('', '');
+        shift @$connect_info while $connect_info->[0] eq '';
+    } else {
+        ($user, $password) = splice @$connect_info, 0, 2;
+    }
+    
+    ($dsn, $user, $password)
+}
+
 sub _parse_connect_info {
     my ($self, $connect_info) = @_;
 
     my @connect_info = @$connect_info;
 
-    my ($dsn, $user, $password) = splice @connect_info, 0, 3;
+    my ($dsn, $user, $password) = $self->_get_dsn_user_pass(\@connect_info);
 
     tie my %connect_info, 'Tie::IxHash';
     @connect_info{qw/dsn user password/} = ($dsn, $user, $password);
@@ -565,3 +599,5 @@
 =cut
 
 1;
+__END__
+# vim:sts=4 sw=4:

Modified: trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Model/DBIC/Schema.pm
===================================================================
--- trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Model/DBIC/Schema.pm	2009-05-17 21:45:11 UTC (rev 10191)
+++ trunk/Catalyst-Model-DBIC-Schema/lib/Catalyst/Model/DBIC/Schema.pm	2009-05-17 23:20:51 UTC (rev 10192)
@@ -246,6 +246,7 @@
             user   postgres
             password ''
             auto_savepoint 1
+	    quote_char """
             on_connect_do   some SQL statement
             on_connect_do   another SQL statement
         </connect_info>
@@ -270,6 +271,7 @@
           LongTruncOk: 1
           on_connect_do: [ "alter session set nls_date_format = 'YYYY-MM-DD HH24:MI:SS'" ]
           cursor_class: 'DBIx::Class::Cursor::Cached'
+	  quote_char: '"'
 
 The old arrayref style with hashrefs for L<DBI> then L<DBIx::Class> options is also
 supported:

Modified: trunk/Catalyst-Model-DBIC-Schema/t/05testapp.t
===================================================================
--- trunk/Catalyst-Model-DBIC-Schema/t/05testapp.t	2009-05-17 21:45:11 UTC (rev 10191)
+++ trunk/Catalyst-Model-DBIC-Schema/t/05testapp.t	2009-05-17 23:20:51 UTC (rev 10192)
@@ -12,21 +12,44 @@
 my $test_params = [
     [ 'TestSchema', 'DBIC::Schema', '' ],
     [ 'TestSchemaDSN', 'DBIC::Schema', q{fakedsn fakeuser fakepass "{ AutoCommit => 1 }"} ],
+    [ 'TestSchemaDSN', 'DBIC::Schema', q{create=static roles=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 roles=Caching moniker_map="{ roles => \"ROLE\" }" dbi:SQLite:testdb.db on_connect_do="[\"select 1\", \"select 2\"]" quote_char="\""} ],
 ];
 
-plan tests => (2 * @$test_params);
+plan tests => (2 * @$test_params + 2);
 
 my $test_dir   = $FindBin::Bin;
 my $blib_dir   = File::Spec->catdir ($test_dir, '..', 'blib', 'lib');
 my $cat_dir    = File::Spec->catdir ($test_dir, 'TestApp');
 my $catlib_dir = File::Spec->catdir ($cat_dir, 'lib');
+my $schema_dir = File::Spec->catdir ($catlib_dir, 'TestSchemaDSN');
 my $creator    = File::Spec->catfile($cat_dir, 'script', 'testapp_create.pl');
 my $model_dir  = File::Spec->catdir ($catlib_dir, 'TestApp', 'Model');
+my $db         = File::Spec->catdir ($cat_dir, 'testdb.db');
 
 chdir($test_dir);
 system("catalyst.pl TestApp");
 chdir($cat_dir);
 
+# create test db
+open my $sql, '|-', 'sqlite3', $db or die $!;
+print $sql <<'EOF';
+CREATE TABLE users (                       
+        id            INTEGER PRIMARY KEY, 
+        username      TEXT,                
+        password      TEXT,                
+        email_address TEXT,                
+        first_name    TEXT,                
+        last_name     TEXT,                
+        active        INTEGER              
+);
+CREATE TABLE roles (
+        id   INTEGER PRIMARY KEY,
+        role TEXT
+);
+EOF
+close $sql;
+
 foreach my $tparam (@$test_params) {
    my ($model, $helper, $args) = @$tparam;
    system("$^X -I$blib_dir $creator model $model $helper $model $args");
@@ -34,6 +57,16 @@
    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/) {
+      my $glob = File::Spec->catfile($schema_dir, 'Result', '*');
+      my $tables =()= glob($glob);
+      if ($args =~ /constraint/) {
+         is $tables, 1, 'constraint works';
+      } else {
+         is $tables, 2, 'correct number of tables';
+      }
+   }
 }
 
 chdir($test_dir);




More information about the Catalyst-commits mailing list