Version bumped to 0.03002, assorted minor changes
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Row.pm
index 5f4cb17..4308e9c 100644 (file)
@@ -33,7 +33,7 @@ sub new {
   if ($attrs) {
     $new->throw("attrs must be a hashref" ) unless ref($attrs) eq 'HASH';
     while (my ($k, $v) = each %{$attrs}) {
-      $new->store_column($k => $v);
+      $new->store_column($k => $v) if exists $class->_columns->{$k};
     }
   }
   return $new;
@@ -104,7 +104,10 @@ UPDATE query to commit any changes to the object to the db if required.
 sub update {
   my ($self, $upd) = @_;
   $self->throw( "Not in database" ) unless $self->in_storage;
-  my %to_update = %{$upd || {}};
+  if (ref $upd eq 'HASH') {
+    $self->$_($upd->{$_}) for keys %$upd;
+  }
+  my %to_update;
   $to_update{$_} = $self->get_column($_) for $self->is_changed;
   return -1 unless keys %to_update;
   my $rows = $self->storage->update($self->_table_name, \%to_update,
@@ -208,10 +211,11 @@ sub store_column {
   return $self->{_column_data}{$column} = $value;
 }
 
-sub _row_to_object { # WARNING: Destructive to @$row
+sub _row_to_object {
   my ($class, $cols, $row) = @_;
-  my $new = $class->new;
-  $new->store_column($_, shift @$row) for @$cols;
+  my %vals;
+  $vals{$cols->[$_]} = $row->[$_] for 0 .. $#$cols;
+  my $new = $class->new(\%vals);
   $new->in_storage(1);
   return $new;
 }
@@ -258,7 +262,7 @@ sub is_changed {
 
 =head1 AUTHORS
 
-Matt S. Trout <perl-stuff@trout.me.uk>
+Matt S. Trout <mst@shadowcatsystems.co.uk>
 
 =head1 LICENSE