HTML::Paginator

HTML::Paginator is a Object-Oriented pagination for web applications.
Download

HTML::Paginator Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Dodger
  • Publisher web site:
  • http://search.cpan.org/~dodger/HTML-Paginator-0_51/Paginator/Paginator.pm

HTML::Paginator Tags


HTML::Paginator Description

HTML::Paginator is a Object-Oriented pagination for web applications. HTML::Paginator is a Object-Oriented pagination for web applications.SYNOPSIS use CGI; use HTML::Paginator; my $cgi = new CGI; my $page = $cgi->param('page') || 1; my @items = (1..67); my $book = HTML::Paginator->new(25,@items); $book->Name_Item('random item'); @items = $book->Contents($page); print "< html >n < head >n < title >Sample Script< /title >n ", "< /head >n< /html >"; # it bugs me that people use CGI methods for stuff like that # above. Gaaah. print "< body >n", $cgi->h2($book->Page_Header_HTML($page)), "< ul >n"; print " < /li >$_< /li >n" for @items; print "< /ul >n", $book->Page_Nav_HTML($page), "< /body >n< /html >n";HTML::Paginator is an Object-Oriented module intended to make pagination of large lists easy. Using an amazing (or amazingly simple) internal method, it takes your favourite array and it slices, it dices, and it makes Julien Fries out of your array.It's an HTML module because that's where it's most useful. However, a small amount of finagling can make it useful for any interface, really.InstantiationYou create a Paginator object, which I'm calling a 'book' for lack of a better term, by calling the new($@) method, like is done with most OO modules.new takes two or more arguments: the first is the number of items you want per page. The second and all following are the items you want sliced up into seperate pages. For instance, you could pull the results of a SQL query in to be sliced up, and display 10 per page: my @stuff; while (my $row = $my_query->fetchrow_hashref) { push @stuff, $row; } my $book = HTML::Paginator->new(10, @stuff); for my $row ($book->Contents($page) { print $row->{column_to_print}; }It's that easy.Of course, if your database is slow, or you have a huge number of results, you don't want to pull down all of them first. I recommend getting a count, using paginator to slice *that* up, and then working a little programmer magic to get back only the slice of the table you want (Oracle would let you use rownum, while with MySQL you might have to work harder, doing a few small queries to whittle things to where you want them).Then again, who says you're using a database? You could even use this to paginate a huge text document in an external file, with a while() and a counter scalar, maybe. Ahh, this is all your job. I did the slicing.As a note, HTML::Paginator acts like it thinks in terms of 1-indexed arrays. It doesn't, really. It just pretends to with its public methods. This is because while we all know that arrays should be zero-indexed, the user doesn't, and seeing page=0 in their URL looks goofy to them. So we're nice to them. They won't thank you because the web is full of ungrateful bastards, but you can feel nicer about yourself for knowing you were nice to a bastard. Or something. Requirements: · Perl


HTML::Paginator Related Software