Class::DBI::Plugin::RetrieveAll(3pm)

Class::DBI::Plugin::RetrieveAll3pm

More complex retrieve_all() for class::dbi

Usage

        use base 'Class::DBI';
        use Class::DBI::Plugin::RetrieveAll;
        my @by_date = My::Class->retrieve_all_sorted_by("date");
        # or
        __PACKAGE__->retrieve_all_sort_field('date');
        my @by_date = My::Class->retrieve_all;

Overview

This is a simple plugin to a Class::DBI subclass that allows for simple sorting of the results of a retrieve_all().

There are two main ways to use this.

Firstly, we create a new method 'retrieve_all_sorted_by' which takes an argument of how to sort.

We also add a method for 'retrieve_all_sort_field' that sets a default field that any retrieve_all() will use for sorting.

Methods

retrieve_all_sorted_by

        my @by_date = My::Class->retrieve_all_sorted_by("date");

This method will be exported into the calling class, and allows for retrieving all the objects of the class, sorted by the given column.

The argument given will be passed straight through to the database 'as is', and is not checked in any way, so an error here will usually in an error from the database, rather than Class::DBI itself.

This makes it possible to pass more complex ORDER BY clauses through:

        my @by_date = My::Class->retrieve_all_sorted_by("date DESC, reference_no");

retrieve_all_sort_field

  __PACKAGE__->retrieve_all_sort_field('date');

This method changes the default retrieve_all() in the Class to be auto-sorted by the field given. Again this will be passed through directly, so you can have complex ORDER BY clauses.

BUGS and QUERIES

Please direct all correspondence regarding this module to:
[email protected]

Releases

11 releases since Debian 3.1 (Sarge); the text changed 5 times.

  1. 3.1
  2. 4.0–5.0
  3. 6.0–9
  4. 10
  5. 11
  6. 12–13

Author

Tony Bowden

From libclass-dbi-plugin-retrieveall-perl 1.04-5 in Debian 13 (Trixie). Parsed by carta from the page's man source.