Flame has asked for the wisdom of the Perl Monks concerning the following question:

I was just thinking that it would be kinda handy to have a module which could be used to create paged lists for use on websites.

But here's the first question: Has it been done? Then: What would I call it? And of course: How should it work?

As to the third question, I was thinking of something like:
my %format = ( linestart => "", fseperator => "\n", fields => { id => 'Id: $', test => 'Test: $' }, lseperator => "\n\n", lineend => "", ); my @data = ( { id => 1, test => 'Basic Functions', }, { id => 1, test => 'Advanced Functions', } ); my $page = 1; #Which page my $length = 1; #Number of entrys per page print pager(\%format,\@data,$page,$length); ------------ Output: Id: 1 Test: Basic Functions ------------ Or if $page was set to 2 Id: 2 Test: Advanced Functions ------------ Of if $length was 2 (or more) Id: 1 Test: Basic Functions Id: 2 Test: Advanced Functions


I think that's as clear as I can be on this idea... any comments, (answers to the questions I posed above?) etc?



My code doesn't have bugs, it just develops random features.

Flame ~ Lead Programmer: GMS

Replies are listed 'Best First'.
Re: Potential for a New Module?
by valdez (Monsignor) on Aug 06, 2002 at 22:57 UTC

    May be what you are looking for is HTML::Pager: Perl module to handle CGI HTML paging of arbitary data, by the same author of HTML::Template

    Ciao, Valerio

      Well, I see now that there are several options to look at. So a pager module such as that wouldn't be all that useful. Ok, question answered, thanks. (This was mostly to determine weather or not I should extend the effort to build the module or not, as there is no need, then I won't waste time re-inventing the wheel.)

      Thanks for the advice and suggestions, (/me makes a mental note to look into HTML::Template and other template systems.)





      My code doesn't have bugs, it just develops random features.

      Flame ~ Lead Programmer: GMS

Re: Potential for a New Module?
by fuzzyping (Chaplain) on Aug 06, 2002 at 22:21 UTC
    Is there a reason why you need to create static pages, rather than creating the listed pages one page at a time? If not, I highly suggest HTML::Template. Simply passing it a sequence of AoH's (one for each page) will allow you to abstract the HTML from the data. Not to mention, all the saved bit space on your drives. ;-)

    Each "navigation" link would simply contain a hidden sequence within the URI, defining what range of data the AoH should define and pass of to the TMPL_LOOP tags (for example). There's an excellent introductory document for this module here.

    Hope this helps!

    -fp

      Not all of us need, or want, dynamic sites.

      That said, using a templating system is a really good idea. I'd like to see a system that chunks the input data into separate pages, then calls a callback function on each to HTML-ify them. This callback could use HTML::Template, Template Toolkit, XSLT, HTML::FromText, or anything else you care about. (This also has the advantage of working with things other than HTML. If I want to drop in a callback that generates LaTeX sections for a book, I can do so quite easily.)

      Of course, the more general the module gets, the closer it gets to a simple for loop:

      for my $page (@pages) { &process_page($page); }

      ...which isn't precisely CPAN material. :-)

      --
      F o x t r o t U n i f o r m
      Found a typo in this node? /msg me