From: Matt S Trout Date: Fri, 10 Nov 2006 13:38:40 +0000 (+0000) Subject: inflate_result can return an array now. somebody write me tests please X-Git-Tag: v0.07003~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=25dbe178b946f6a68f57e0c7eeaa7603ba4f363c;p=dbsrgits%2FDBIx-Class.git inflate_result can return an array now. somebody write me tests please --- diff --git a/Changes b/Changes index cb59335..4a85866 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ Revision history for DBIx::Class 0.07003 2006-XX-XX XX:XX:XX + - Tweaks to resultset to allow inflate_result to return an array - Fix UTF8Columns to work under Perl <= 5.8.0 - Fix up new_result in ResultSet to avoid alias-related bugs - Made new/update/find handle 'single' rel accessor correctly diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 64bcd4e..32b42b5 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -536,7 +536,7 @@ sub single { $attrs->{where}, $attrs ); - return (@data ? $self->_construct_object(@data) : ()); + return (@data ? ($self->_construct_object(@data))[0] : ()); } # _is_unique_query @@ -721,22 +721,28 @@ sub next { $self->{all_cache_position} = 1; return ($self->all)[0]; } + if ($self->{stashed_objects}) { + my $obj = shift(@{$self->{stashed_objects}}); + delete $self->{stashed_objects} unless @{$self->{stashed_objects}}; + } my @row = ( exists $self->{stashed_row} ? @{delete $self->{stashed_row}} : $self->cursor->next ); return unless (@row); - return $self->_construct_object(@row); + my ($row, @more) = $self->_construct_object(@row); + $self->{stashed_objects} = \@more if @more; + return $row; } sub _construct_object { my ($self, @row) = @_; my $info = $self->_collapse_result($self->{_attrs}{as}, \@row); - my $new = $self->result_class->inflate_result($self->result_source, @$info); - $new = $self->{_attrs}{record_filter}->($new) + my @new = $self->result_class->inflate_result($self->result_source, @$info); + @new = $self->{_attrs}{record_filter}->(@new) if exists $self->{_attrs}{record_filter}; - return $new; + return @new; } sub _collapse_result {