release for 0.07, ->require and connect_info args stuff
[catagits/Catalyst-Model-DBIC-Schema.git] / lib / Catalyst / Helper / Model / DBIC / Schema.pm
index 0546c63..12d6cbd 100644 (file)
@@ -10,15 +10,23 @@ Catalyst::Helper::Model::DBIC::Schema - Helper for DBIC Schema Models
 
 =head1 SYNOPSIS
 
-    script/create.pl model Foo DBIC::Schema Foo::SchemaClass [ dsn user password ]
+  script/create.pl model Foo DBIC::Schema Foo::SchemaClass [ connect_info arguments ]
 
-    Where:
-      Foo is the short name for the Model class being generated
-      Foo::SchemaClass is the fully qualified classname of your Schema,
-        which isa DBIx::Class::Schema defined elsewhere.
-      dsn, user, and password are optional if connection info is already
-        defined in your Schema class (as it would be in the case of
-        DBIx::Class::Schema::Loader).
+  Where:
+    Foo is the short name for the Model class being generated
+    Foo::SchemaClass is the fully qualified classname of your Schema,
+      which isa DBIx::Class::Schema defined elsewhere.
+    connect_info arguments are the same as what DBIx::Class::Schema::connect
+      expects, and are storage_type-specific.  For DBI-based storage, these
+      arguments are the dsn, username, password, and connect options,
+      respectively.
+
+=head1 TYPICAL EXAMPLES
+
+  script/myapp_create.pl model Foo DBIC::Schema FooSchema dbi:mysql:foodb myuname mypass '{ AutoCommit => 1 }'
+
+  # -or, if the schema already has connection info and you want to re-use that:
+  script/myapp_create.pl model Foo DBIC::Schema FooSchema
 
 =head1 DESCRIPTION
 
@@ -31,15 +39,16 @@ Helper for the DBIC Schema Models.
 =cut
 
 sub mk_compclass {
-    my ( $self, $helper, $schema_class, $dsn, $user, $pass ) = @_;
+    my ( $self, $helper, $schema_class, @connect_info) = @_;
 
     $helper->{schema_class} = $schema_class || '';
 
-    if(defined($dsn)) {
+    if(@connect_info) {
         $helper->{setup_connect_info} = 1;
-        $helper->{dsn}         = $dsn  || '';
-        $helper->{user}        = $user || '';
-        $helper->{pass}        = $pass || '';
+        for(@connect_info) {
+            $_ = qq{'$_'} if $_ !~ /^\s*[[{]/;
+        }
+        $helper->{connect_info} = \@connect_info;
     }
 
     my $file = $helper->{file};
@@ -74,6 +83,8 @@ it under the same terms as Perl itself.
 
 __DATA__
 
+=begin pod_to_ignore
+
 __compclass__
 package [% class %];
 
@@ -82,19 +93,10 @@ use base 'Catalyst::Model::DBIC::Schema';
 
 __PACKAGE__->config(
     schema_class => '[% schema_class %]',
-    [% IF setup_connect_info %]
-    connect_info => [ '[% dsn %]',
-                      '[% user %]',
-                      '[% pass %]',
-                      {
-                          RaiseError         => 1,
-                          PrintError         => 0,
-                          ShowErrorStatement => 1,
-                          TraceLevel         => 0,
-                          AutoCommit         => 1,
-                      }
-                    ],
-    [% END %]
+    [% IF setup_connect_info %]connect_info => [
+        [% FOREACH arg = connect_info %][% arg %],
+        [% END %]
+    ],[% END %]
 );
 
 =head1 NAME