From: Matt S Trout Date: Fri, 15 Jul 2011 10:49:30 +0000 (+0000) Subject: fix $rs->populate([]) to be a no-op rather than an exception X-Git-Tag: v0.08194~12 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ce855fffdd5cf13e9fd29ad9883ab7cbb9a7b22a;p=dbsrgits%2FDBIx-Class.git fix $rs->populate([]) to be a no-op rather than an exception --- diff --git a/Changes b/Changes index d8613d7..9d03176 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,7 @@ Revision history for DBIx::Class * Fixes - Fix spurious test failures caused by use of Data::Compare + - Fix $rs->populate([]) to be a no-op rather than an exception 0.08193 2011-07-14 17:00 (UTC) * New Features / Changes diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index bf4b1d8..4c5b961 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1972,6 +1972,8 @@ sub populate { # cruft placed in standalone method my $data = $self->_normalize_populate_args(@_); + return unless @$data; + if(defined wantarray) { my @created; foreach my $item (@$data) { @@ -2076,7 +2078,10 @@ sub _normalize_populate_args { my ($self, $arg) = @_; if (ref $arg eq 'ARRAY') { - if (ref $arg->[0] eq 'HASH') { + if (!@$arg) { + return []; + } + elsif (ref $arg->[0] eq 'HASH') { return $arg; } elsif (ref $arg->[0] eq 'ARRAY') { diff --git a/t/101populate_rs.t b/t/101populate_rs.t index a2a2615..6caf01e 100644 --- a/t/101populate_rs.t +++ b/t/101populate_rs.t @@ -686,4 +686,6 @@ ARRAYREF_OF_ARRAYREF_STYLE: { } } +ok(eval { $art_rs->populate([]); 1 }, "Empty populate runs but does nothing"); + done_testing;