C::M::DBIC::Schema -- kill a couple of warnings
[catagits/Catalyst-Model-DBIC-Schema.git] / lib / Catalyst / Helper / Model / DBIC / Schema.pm
index a42b94e..5a771cc 100644 (file)
@@ -2,8 +2,9 @@ package Catalyst::Helper::Model::DBIC::Schema;
 
 use strict;
 use warnings;
+no warnings 'uninitialized';
 
-our $VERSION = '0.21';
+our $VERSION = '0.23';
 
 use Carp;
 use UNIVERSAL::require;
@@ -59,6 +60,11 @@ Use of either of the C<create=> options requires L<DBIx::Class::Schema::Loader>.
   #  and a Model which references it:
   script/myapp_create.pl model CatalystModelName DBIC::Schema MyApp::SchemaClass create=static dbi:mysql:foodb myuname mypass
 
+  # 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$' dbi:Pg:dbname=foodb myuname mypass
+
+  # See DBIx::Class::Schema::Loader::Base for list of options
+
   # Create a dynamic DBIx::Class::Schema::Loader-based Schema,
   #  and a Model which references it:
   script/myapp_create.pl model CatalystModelName DBIC::Schema MyApp::SchemaClass create=dynamic dbi:mysql:foodb myuname mypass
@@ -88,6 +94,17 @@ sub mk_compclass {
         shift @connect_info;
     }
 
+    my %extra_args;
+    while (@connect_info && $connect_info[0] !~ /^dbi:/) {
+        my ($key, $val) = split /=/, shift(@connect_info);
+
+        if ((my @vals = split /,/ => $val) > 1) {
+            $extra_args{$key} = \@vals;
+        } else {
+            $extra_args{$key} = $val;
+        }
+    }
+
     if(@connect_info) {
         $helper->{setup_connect_info} = 1;
         my @helper_connect_info = @connect_info;
@@ -134,23 +151,38 @@ sub mk_compclass {
             $compatible = 1 if $schema_code =~ /->load_classes/;
         }
 
-        if ($compatible) {
-            make_schema_at(
-                $schema_class,
-                { relationships => 1 },
-                \@loader_connect_info,
-            );
-        } else { # use some saner defaults
-            make_schema_at(
-                $schema_class,
-                {
-                    relationships => 1,
-                    use_namespaces => 1,
-                    components => ['InflateColumn::DateTime']
-                },
-                \@loader_connect_info,
-            );
+        my @components = $compatible ? () : ('InflateColumn::DateTime');
+
+        if (exists $extra_args{components}) {
+            $extra_args{components} = [ $extra_args{components} ]
+                unless ref $extra_args{components};
+
+            push @components, @{ delete $extra_args{components} };
+        }
+
+        for my $re_opt (qw/constraint exclude/) {
+            $extra_args{$re_opt} = qr/$extra_args{$re_opt}/
+                if exists $extra_args{$re_opt};
         }
+
+        if (exists $extra_args{moniker_map}) {
+            die "The moniker_map option is not currently supported by this helper, please write your own DBIx::Class::Schema::Loader script if you need it."
+        }
+
+        make_schema_at(
+            $schema_class,
+            {
+                relationships => 1,
+                (%extra_args ? %extra_args : ()),
+                (!$compatible ? (
+                    use_namespaces => 1
+                ) : ()),
+                (@components ? (
+                    components => \@components
+                ) : ())
+            },
+            \@loader_connect_info,
+        );
     }
 
     my $file = $helper->{file};