Added multi-create object support to Schema->populate and created a test for this...
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Schema.pm
index fa26110..db2a8f6 100644 (file)
@@ -3,6 +3,7 @@ package DBIx::Class::Schema;
 use strict;
 use warnings;
 
+use DBIx::Class::Exception;
 use Carp::Clan qw/^DBIx::Class/;
 use Scalar::Util qw/weaken/;
 use File::Spec;
@@ -15,7 +16,7 @@ __PACKAGE__->mk_classdata('source_registrations' => {});
 __PACKAGE__->mk_classdata('storage_type' => '::DBI');
 __PACKAGE__->mk_classdata('storage');
 __PACKAGE__->mk_classdata('exception_action');
-__PACKAGE__->mk_classdata('stacktrace' => 0);
+__PACKAGE__->mk_classdata('stacktrace' => $ENV{DBIC_TRACE} || 0);
 
 =head1 NAME
 
@@ -678,7 +679,6 @@ sub connection {
   my $storage = $storage_class->new($self);
   $storage->connect_info(\@info);
   $self->storage($storage);
-  $self->on_connect() if($self->can('on_connect'));
   return $self;
 }
 
@@ -851,7 +851,15 @@ sub populate {
     }
     return @created;
   }
-  $self->storage->insert_bulk($self->source($name), \@names, $data);
+  my @results_to_create;
+  foreach my $datum (@$data) {
+    my %result_to_create;
+    foreach my $index (0..$#names) {
+      $result_to_create{$names[$index]} = $$datum[$index];
+    }
+    push @results_to_create, \%result_to_create;
+  }
+  $rs->populate(\@results_to_create);
 }
 
 =head2 exception_action
@@ -894,9 +902,9 @@ Example:
 
 =back
 
-This alters the behavior of the default L</throw_exception> action.  It
-uses C<croak> if C<stacktrace> is false, or C<confess> if C<stacktrace>
-is true.  The default is false.
+Whether L</throw_exception> should include stack trace information.
+Defaults to false normally, but defaults to true if C<$ENV{DBIC_TRACE}>
+is true.
 
 =head2 throw_exception
 
@@ -908,16 +916,16 @@ is true.  The default is false.
 
 Throws an exception. Defaults to using L<Carp::Clan> to report errors from
 user's perspective.  See L</exception_action> for details on overriding
-this method's behavior.  If L</stacktrace> is turned on, C<throw_exception>
-will use C<confess> instead of C<croak>.
+this method's behavior.  If L</stacktrace> is turned on, C<throw_exception>'s
+default behavior will provide a detailed stack trace.
 
 =cut
 
 sub throw_exception {
   my $self = shift;
-  if(!$self->exception_action || !$self->exception_action->(@_)) {
-    $self->stacktrace ? confess @_ : croak @_;
-  }
+
+  DBIx::Class::Exception->throw($_[0], $self->stacktrace)
+    if !$self->exception_action || !$self->exception_action->(@_);
 }
 
 =head2 deploy (EXPERIMENTAL)