release
[catagits/Catalyst-Model-DBIC-Schema.git] / lib / Catalyst / Helper / Model / DBIC / Schema.pm
index 049ff7e..b58a093 100644 (file)
@@ -4,7 +4,7 @@ use namespace::autoclean;
 use Moose;
 no warnings 'uninitialized';
 
-our $VERSION = '0.24';
+our $VERSION = '0.30';
 
 use Carp;
 use Tie::IxHash ();
@@ -12,7 +12,6 @@ use Data::Dumper ();
 use List::Util 'first';
 use MooseX::Types::Moose qw/Str HashRef Bool ArrayRef/;
 use Catalyst::Model::DBIC::Schema::Types 'CreateOption';
-use Moose::Autobox;
 use List::MoreUtils 'firstidx';
 use Scalar::Util 'looks_like_number';
 
@@ -161,7 +160,7 @@ sub mk_compclass {
 sub BUILD {
     my $self   = shift;
     my $helper = $self->helper;
-    my @args   = $self->args->flatten if $self->args;
+    my @args   = @{ $self->args || [] };
 
     $helper->{schema_class} = $self->schema_class;
 
@@ -174,7 +173,7 @@ sub BUILD {
         $self->traits(\@traits);
 
         $helper->{traits} = '['
-            .(join ',' => map { qq{'$_'} } ($self->traits->flatten))
+            .(join ',' => map { qq{'$_'} } @traits)
             .']';
 
         splice @args, $traits_idx, 1, ();
@@ -188,16 +187,21 @@ sub BUILD {
             $self->_parse_loader_args(\@args);
 
             $helper->{loader_args} = $self->_build_helper_loader_args;
+        }
+    }
 
-            if (first { /^dbi:/i } @args) {
-                $helper->{setup_connect_info} = 1;
+    my $dbi_dsn_part;
+    if (first { ($dbi_dsn_part) = /^(dbi):/i } @args) {
+        die
+qq{DSN must start with 'dbi:' not '$dbi_dsn_part' (case matters!)}
+            if $dbi_dsn_part ne 'dbi';
 
-                $helper->{connect_info} =
-                    $self->_build_helper_connect_info(\@args);
+        $helper->{setup_connect_info} = 1;
 
-                $self->_parse_connect_info(\@args);
-            }
-        }
+        $helper->{connect_info} =
+            $self->_build_helper_connect_info(\@args);
+
+        $self->_parse_connect_info(\@args);
     }
 
     $helper->{generator} = ref $self;
@@ -269,7 +273,7 @@ sub _read_loader_args {
 
     my %loader_args;
 
-    while (@$args && $args->[0] !~ /^dbi:/) {
+    while (@$args && $args->[0] !~ /^dbi:/i) {
         my ($key, $val) = split /=/, shift(@$args), 2;
 
         if ($self->_is_struct($val)) {
@@ -400,7 +404,7 @@ sub _get_dsn_user_pass {
 
     if ($dsn =~ /sqlite/i) {
         ($user, $password) = ('', '');
-        shift @$connect_info while $connect_info->[0] eq '';
+        shift @$connect_info while @$connect_info and $connect_info->[0] eq '';
     } else {
         ($user, $password) = splice @$connect_info, 0, 2;
     }