Luke Reeves > DBI-ResultPager-0.9.2 > DBI::ResultPager

Download:
DBI-ResultPager-0.9.2.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.9.2   Source  

NAME ^

DBI::ResultPager - creates an HTML-based pager for DBI result sets.

SYNOPSIS ^

 # Create a pageable result set
 use DBI::ResultPager;
 
 my $rp = DBI::ResultPager->new;
 $rp->dbh($dbh);
 $rp->query('select books.title, authors.name
             from books
             inner join (books.author_id = authors.id)');
 $rp->display();

 # The same result set, but sorted with nicer column headings
 my $rp = DBI::ResultPager->new;
 $rp->dbh($dbh);
 $rp->query('select books.title as "Title", 
             authors.name as "Author"
             from books
             inner join (books.author_id = authors.id)');
 $rp->defaultOrder('Title');
 $rp->display();

 # Adding a custom formatter to build links
 my $rp = DBI::ResultPager->new;
 $rp->dbh($dbh);
 $rp->query('select books.title as "Title", 
             books.isbn as "ISBN",
             authors.name as "Author"
             from books
             inner join (books.author_id = authors.id)');
 $rp->addColumnFormatter('ISBN', \&linkISBN);
 $rp->display();

 sub linkISBN {
     my($isbn) = shift;
     return '<a href="http://isbndb.com/search-all.html?kw=' .
         $isbn . '">ISBNdb</a>';
 }

 # Adding a custom column and hiding an identity column
 my $rp = DBI::ResultPager->new;
 $rp->dbh($dbh);
 $rp->query('select books.id,
             books.title as "Title", 
             from books');
 $rp->hideColumn('books.id');
 $rp->addCustomColumn('Functions', \&bookFunctions);
 $rp->display();
 
 sub bookFunctions {
   my (@row) = (@_);
   return '<a href="delete.cgi?id=' . $row[0] . '">delete</a>';
 }

 # Set the number of results per page:
 $rp->perPage(20);

 # Vertically align the outputted columns:
 $rp->alignRows('top');

 # Get the outputted table as a scalar
 my $output = $rp->getOutput();

DESCRIPTION ^

This class is a quick and easy method of paging result sets returned from the DBI database interface. It takes a standard SQL query along with a database handle and performs the query, inserting the resultant rows into a pageable HTML table. Various options such as sort order can be adjusted, and columns can have formatters attached. Columns can also be hidden, and custom columns can be added to the output.

METHODS ^

dbh

This sets the DBI database handle for query execution.

addColumnFormatter (name, formatter)

Adds a custom formatting routine to a column. When a row of that column is rendered, the customer format routine is called with two parameters - the value of the data in that cell, and a list reference containing the current row of the resultset. The list reference is useful for referring to other elements in the current row.

SOURCE AVAILABILITY ^

The source for this project should always be available from CPAN. Other than that it may be found at https://neuro-tech.net/.

AUTHOR ^

        Original code:          Luke Reeves <luke@neuro-tech.net>
                                https://neuro-tech.net/

COPYRIGHT ^

Copyright (c) 2005 Luke Reeves <luke@neuro-tech.net>

DBI::ResultPager is free software. You can redistribute it and/or modify it under the same terms as Perl itself.

CREDITS ^

 Luke Reeves <luke@neuro-tech.net>

SEE ALSO ^

perl(1), DBI(3).

syntax highlighting: