[Dbix-class] Per the design of a method

Peter Rabbitson rabbit+dbic at rabbit.us
Thu Jun 16 17:17:06 GMT 2011


dorian taylor wrote:
> On Thu, Jun 16, 2011 at 9:24 AM, Dan Horne <dan.horne at redbone.co.nz> wrote:
>> I'm not sure that I understand your query. The resultset has a Data::Page object which has the total number of rows, and should also handle the pagination for you:
> 
> Ah. Perhaps I should come clean. I'm not actually looking for
> pagination but absolute offsets. I just wanted to avoid confusion but
> it looks like I created it instead. The net effect though is that
> Data::Page does nothing for me.
> 
> This is what I'm trying to do:
> 
> sub foo {
>     my ($self, $rs, $start, $end) = @_;
> 
>     # we get absolute values one way but ResultSet wants 'em a different way
>     my ($limit, $offset) = convert_to_limit_offset($start, $end);
> 
>     # if I put the limit/offset in the resultset passed in, this will be wrong
>     my $total = $rs->count;

This won't be wrong - ->count returns how many objects you would receive
via ->all/->next. If you want full count of the underlying source with
all limits removed - keep the original resultset around. If you do not care
about WHERE conditions either - $rs->result_source->resultset->count will
do it for you.

Cheers



More information about the DBIx-Class mailing list