Activator

 view release on metacpan or  search on metacpan

lib/Activator/Pager.pm  view on Meta::CPAN

    $self->{from} = $total > 0 ? $offset+1 : 0;
    $self->{to}   = $offset+$set_size < $total ? $offset+$set_size : $total;

    ## last page number
    #
    # Last page is total/length when evenly divisible. We mod them, if
    # there is remainder, add 1 for the last page. EG: 101/10 == 10
    # pages + 1 on the last page
    #
    # this new hotness courtesy Frank Wallingford
    # TODO: write pager tests, use this formula
    #$self->{last_page} = int(($total + ( $page_size - 1 ) ) / $page_size );

    # old and crufty
    $self->{last_page} = int($total/$page_size) + ( ($total % $page_size > 0) ? 1 : 0 );

    ## last offset
    #
    # Similar to above, we need to subtract 1 length when evenly
    # divisible so that we don't offset off the end of the available
    # results. If there is a remainder, subtract nothing.
    #WARN( qq{  ($self->{last_page} * $page_size) - ( ($total % $page_size > 0) ? 0 : $page_size)  });

    # this new hotness courtesy Frank Wallingford
    # TODO: write pager tests, use this formula
    #$self->{last_offset} = int( ( $total - 1 ) / $page_size ) + 1;

    # old and crufty
    $self->{last_offset} = int($total/$page_size) * $page_size - ( ($total % $page_size > 0) ? 0 : $page_size ); ;


    ## cur page offset
    $self->{cur_page} = int( $offset / $page_size ) + 1;

    ## prev



( run in 0.953 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )