From: Rafael Kitover Date: Thu, 22 Oct 2009 09:10:38 +0000 (+0000) Subject: stringify values passed to populate/insert_bulk X-Git-Tag: v0.08113~29 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=03e7644dde21b79305ab80e1d3d9d5ca2948dcd5;p=dbsrgits%2FDBIx-Class.git stringify values passed to populate/insert_bulk --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 31bc5b4..fbd676f 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1796,8 +1796,10 @@ sub populate { } else { my ($first, @rest) = @$data; + require overload; my @names = grep { - (not ref $first->{$_}) || (ref $first->{$_} eq 'SCALAR') + (not ref $first->{$_}) || (ref $first->{$_} eq 'SCALAR') || + (overload::Method($first->{$_}, '""')) } keys %$first; my @rels = grep { $self->result_source->has_relationship($_) } keys %$first; diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 86b7aca..44fe102 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1352,22 +1352,20 @@ sub insert_bulk { next unless ref $first_val eq 'SCALAR'; $colvalues{ $cols->[$i] } = $first_val; -## This is probably unnecessary since $rs->populate only looks at the first -## slice anyway. -# if (grep { -# ref $_ eq 'SCALAR' && $$_ eq $$first_val -# } map $data->[$_][$i], (1..$#$data)) == (@$data - 1); } - # check for bad data + # check for bad data and stringify stringifiable objects my $bad_slice = sub { my ($msg, $col_idx, $slice_idx) = @_; $self->throw_exception(sprintf "%s for column '%s' in populate slice:\n%s", $msg, $cols->[$col_idx], - Data::Dumper::Concise::Dumper({ - map { $cols->[$_] => $data->[$slice_idx][$_] } (0 .. $#$cols) - }), + do { + local $Data::Dumper::Maxdepth = 1; # don't dump objects, if any + Data::Dumper::Concise::Dumper({ + map { $cols->[$_] => $data->[$slice_idx][$_] } (0 .. $#$cols) + }), + } ); }; @@ -1393,8 +1391,14 @@ sub insert_bulk { } } elsif (my $reftype = ref $val) { - $bad_slice->("$reftype reference found where bind expected", - $col_idx, $datum_idx); + require overload; + if (overload::Method($val, '""')) { + $datum->[$col_idx] = "".$val; + } + else { + $bad_slice->("$reftype reference found where bind expected", + $col_idx, $datum_idx); + } } } }