Slicing a paged ResultSet does not do what I expected:
$ my $files = $schema->resultset('File');
$ $files = $files->search( undef, { rows => 5 } );
$ $files = $files->page( 3 );
$ my $count = $files->count;
5
$ map { $_->id } $files->all;
$ARRAY1 = [
13,
14,
15,
16,
17
];
$ map { $_->id } $files->slice( $count-1, $count-1 );
9
I would have expected '17', since it was the last item of the
ResultSet in question.
After reading the source, I became convinced that this was not by
design. The slice method was querying $self->{attr}{offset}, which was
bypassing the offset applied by the page. The new (sliced) ResultSet
retained the page attribute of the old ResultSet, which didn't seem
right either.
I've attached a simple patch which aims to fix the two issues above,
which also happens to bring the behavior back within my expectation.
If '17' shouldn't be the answer to the last line in my re.pl output,
let's straighten me out and perhaps I can instead patch the POD.
The patch currently only touches the core file. I'm hoping to get some
guidance about the appropriate place to put tests for this issue.
Existing tests all pass except POD coverage (not related to my
change).
Also, I apologize, I'm not familiar with the the 0.8/0.9 versioning
convention. I applied my changes to 0.08/trunk from SVN. Please let me
know if that's not the right place.
Thanks!
/rdj
Index: 0.08/trunk/lib/DBIx/Class/ResultSet.pm
===================================================================
--- 0.08/trunk/lib/DBIx/Class/ResultSet.pm (revision 4093)
+++ 0.08/trunk/lib/DBIx/Class/ResultSet.pm (working copy)
@@ -705,9 +705,10 @@
sub slice {
my ($self, $min, $max) = @_;
my $attrs = {}; # = { %{ $self->{attrs} || {} } };
- $attrs->{offset} = $self->{attrs}{offset} || 0;
+ $attrs->{offset} = $self->_resolved_attrs->{offset} || 0;
$attrs->{offset} += $min;
$attrs->{rows} = ($max ? ($max - $min + 1) : 1);
+ $attrs->{page} = undef();
return $self->search(undef(), $attrs);
#my $slice = (ref $self)->new($self->result_source, $attrs);
#return (wantarray ? $slice->all : $slice);
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[EMAIL PROTECTED]