release 0.06, fixed pod_to_ignore stuff, added an optional half-decent helper test
[catagits/Catalyst-Model-DBIC-Schema.git] / lib / Catalyst / Helper / Model / DBIC / Schema.pm
index cc34ed9..19ab06a 100644 (file)
@@ -1,6 +1,8 @@
 package Catalyst::Helper::Model::DBIC::Schema;
 
 use strict;
+use warnings;
+use Carp;
 
 =head1 NAME
 
@@ -8,11 +10,19 @@ 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 [ dsn user password ]
+
+    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).
 
 =head1 DESCRIPTION
 
-Helper for the DBIC Plain Models.
+Helper for the DBIC Schema Models.
 
 =head2 METHODS
 
@@ -21,19 +31,33 @@ Helper for the DBIC Plain Models.
 =cut
 
 sub mk_compclass {
-    my ( $self, $helper, $schemaclass, $dsn, $user, $pass ) = @_;
-    $helper->{schemaclass} = $schemaclass || '';
-    $helper->{dsn}         = $dsn  || '';
-    $helper->{user}        = $user || '';
-    $helper->{pass}        = $pass || '';
+    my ( $self, $helper, $schema_class, $dsn, $user, $pass ) = @_;
+
+    $helper->{schema_class} = $schema_class || '';
+
+    if(defined($dsn)) {
+        $helper->{setup_connect_info} = 1;
+        $helper->{dsn}         = $dsn  || '';
+        $helper->{user}        = $user || '';
+        $helper->{pass}        = $pass || '';
+    }
+
     my $file = $helper->{file};
     $helper->render_file( 'compclass', $file );
 }
 
 =head1 SEE ALSO
 
+General Catalyst Stuff:
+
 L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>,
-L<Catalyst::Response>, L<Catalyst::Helper>
+L<Catalyst::Response>, L<Catalyst::Helper>, L<Catalyst>,
+
+Stuff related to DBIC and this Model style:
+
+L<DBIx::Class>, L<DBIx::Class::Schema>,
+L<DBIx::Class::Schema::Loader>, L<Catalyst::Model::DBIC::Schema>,
+L<Catalyst::Helper::Model::DBIC::SchemaLoader>
 
 =head1 AUTHOR
 
@@ -46,8 +70,12 @@ it under the same terms as Perl itself.
 
 =cut
 
+1;
+
 __DATA__
 
+=begin pod_to_ignore
+
 __compclass__
 package [% class %];
 
@@ -55,7 +83,8 @@ use strict;
 use base 'Catalyst::Model::DBIC::Schema';
 
 __PACKAGE__->config(
-    schema_class => '[% schemaclass %]
+    schema_class => '[% schema_class %]',
+    [% IF setup_connect_info %]
     connect_info => [ '[% dsn %]',
                       '[% user %]',
                       '[% pass %]',
@@ -67,11 +96,12 @@ __PACKAGE__->config(
                           AutoCommit         => 1,
                       }
                     ],
+    [% END %]
 );
 
 =head1 NAME
 
-[% class %] - Catalyst DBIC Plain Model
+[% class %] - Catalyst DBIC Schema Model
 
 =head1 SYNOPSIS
 
@@ -79,7 +109,8 @@ See L<[% app %]>
 
 =head1 DESCRIPTION
 
-Catalyst::Model::DBIC::Schema Model
+L<Catalyst::Model::DBIC::Schema> Model using schema
+L<[% schema_class %]>
 
 =head1 AUTHOR