Data::Paginated - paginate a list of data


Data-Paginated documentation Contained in the Data-Paginated distribution.

Index


Code Index:

NAME

Top

Data::Paginated - paginate a list of data

SYNOPSIS

Top

	my $paginator = Data::Paginated->new({
		entries => \@my_list,
		entries_per_page => $entries_per_page, 
		current_page => $current_page,
	});

	my @to_print = $paginator->page_data;

DESCRIPTION

Top

Data::Paginated is a thin wrapper around Data::Pageset which adds the extra functionality of being able to get all the entries from a list that are on a given page.

METHODS

Top

new

	my $paginator = Data::Paginated->new({
		entries => \@my_list,
		entries_per_page => $entries_per_page,
		current_page => $current_page,
	});

This can take all the arguments that can be passed to Data::Pageset, with the exception that instead of passing simply the total number of items in question, you actually pass the items as a reference.

page_data

	my @to_print = $paginator->page_data;

This returns a list of the entries that will be on the current page.

So, if you have a list of [ 1 .. 10 ], 3 entries per page, and current page is 2, this will return (4, 5, 6).

AUTHOR

Top

Tony Bowden

BUGS and QUERIES

Top

Please direct all correspondence regarding this module to: bug-Data-Paginated@rt.cpan.org

COPYRIGHT AND LICENSE

Top

SEE ALSO

Top

Data::Pageset, Data::Page.


Data-Paginated documentation Contained in the Data-Paginated distribution.
package Data::Paginated;

our $VERSION = '1.01';

use strict;
use warnings;

use base 'Data::Pageset';

use Carp;

sub new {
	my ($class, $conf) = @_;
	my $entries = delete $conf->{entries} or croak "entries must be supplied";
	my $self = $class->SUPER::new({ %$conf, total_entries => scalar @$entries });
	$self->{__DATA_PAGINATED_ENTRIES} = $entries;
	return $self;
}

sub page_data {
	my $self = shift;
	return @{ $self->{__DATA_PAGINATED_ENTRIES} }
		[ $self->first - 1 .. $self->last - 1 ];
}

1;