Class-DBI-Plugin-RetrieveAll-1.04/0000755000175200017520000000000010362702700015314 5ustar tonytonyClass-DBI-Plugin-RetrieveAll-1.04/t/0000755000175200017520000000000010362702700015557 5ustar tonytonyClass-DBI-Plugin-RetrieveAll-1.04/t/01.t0000644000175200017520000000307310103422000016150 0ustar tonytonyuse strict; use Test::More; BEGIN { eval "use DBD::SQLite"; plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 4); } package My::Film; use base 'Class::DBI'; use Class::DBI::Plugin::RetrieveAll; use File::Temp qw/tempfile/; my (undef, $DB) = tempfile(); my @DSN = ("dbi:SQLite:dbname=$DB", '', '', { AutoCommit => 1 }); END { unlink $DB if -e $DB } __PACKAGE__->set_db(Main => @DSN); __PACKAGE__->table('Movies'); __PACKAGE__->columns(All => qw/id title year/); sub CONSTRUCT { shift->db_Main->do( qq{ CREATE TABLE Movies ( id INTEGER PRIMARY KEY, title VARCHAR(255), year INTEGER ) } ); } package main; My::Film->CONSTRUCT; my %films = ( Veronique => 1991, Red => 1994, White => 1994, Blue => 1993, Dekalog => 1988, Hospital => 1976, Heaven => 2002, ); while (my ($title, $year) = each %films) { My::Film->create({ title => $title, year => $year }); } { my @films = My::Film->retrieve_all; is @films, 7, "Got 7 films"; } { my @films = My::Film->retrieve_all_sorted_by('title'); is_deeply [ map $_->title, @films ], [qw/Blue Dekalog Heaven Hospital Red Veronique White/], "Sorted by title"; } { my @films = My::Film->retrieve_all_sorted_by('year, title DESC'); is_deeply [ map $_->title, @films ], [qw/Hospital Dekalog Veronique Blue White Red Heaven/], "Compound sort"; } My::Film->retrieve_all_sort_field('title'); { my @films = My::Film->retrieve_all; is_deeply [ map $_->title, @films ], [qw/Blue Dekalog Heaven Hospital Red Veronique White/], "Sorted by title"; } Class-DBI-Plugin-RetrieveAll-1.04/t/pod.t0000644000175200017520000000020110320462102016510 0ustar tonytonyuse Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); Class-DBI-Plugin-RetrieveAll-1.04/t/pod-coverage.t0000644000175200017520000000024110320462102020305 0ustar tonytonyuse Test::More; eval "use Test::Pod::Coverage 1.00"; plan skip_all => "Test::Pod::Coverage 1.00 required for testing POD coverage" if $@; all_pod_coverage_ok(); Class-DBI-Plugin-RetrieveAll-1.04/lib/0000755000175200017520000000000010362702700016062 5ustar tonytonyClass-DBI-Plugin-RetrieveAll-1.04/lib/Class/0000755000175200017520000000000010362702700017127 5ustar tonytonyClass-DBI-Plugin-RetrieveAll-1.04/lib/Class/DBI/0000755000175200017520000000000010362702700017525 5ustar tonytonyClass-DBI-Plugin-RetrieveAll-1.04/lib/Class/DBI/Plugin/0000755000175200017520000000000010362702700020763 5ustar tonytonyClass-DBI-Plugin-RetrieveAll-1.04/lib/Class/DBI/Plugin/RetrieveAll.pm0000644000175200017520000000544610362702640023553 0ustar tonytonypackage Class::DBI::Plugin::RetrieveAll; our $VERSION = '1.04'; use strict; use warnings; =head1 NAME Class::DBI::Plugin::RetrieveAll - more complex retrieve_all() for Class::DBI =head1 SYNOPSIS 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; =head1 DESCRIPTION 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. =head1 METHODS =head2 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"); =head2 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. =cut sub import { my $caller = caller(); no strict 'refs'; $caller->set_sql(retrieve_all_sorted => <<''); SELECT __ESSENTIAL__ FROM __TABLE__ ORDER BY %s *{"$caller\::retrieve_all_sorted_by"} = sub { my ($class, $order_by) = @_; return $class->sth_to_objects($class->sql_retrieve_all_sorted($order_by)); }; $caller->mk_classdata('__plugin_retall_sortfield'); *{"$caller\::retrieve_all_sort_field"} = sub { my ($class, $field) = @_; $class->__plugin_retall_sortfield($field); }; # I hate that SUPER means *my* SUPER *now* - not $class->SUPER then my $super = $caller->can('retrieve_all'); *{"$caller\::retrieve_all"} = sub { my $class = shift; my $field = $class->__plugin_retall_sortfield or return $super->($class); return $class->retrieve_all_sorted_by($field); }; } =head1 AUTHOR Tony Bowden =head1 BUGS and QUERIES Please direct all correspondence regarding this module to: bug-Class-DBI-Plugin-RetrieveAll@rt.cpan.org =head1 COPYRIGHT and LICENSE Copyright (C) 2004-2006 Kasei. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; Class-DBI-Plugin-RetrieveAll-1.04/README0000644000175200017520000000400410362702665016204 0ustar tonytonyNAME Class::DBI::Plugin::RetrieveAll - more complex retrieve_all() for Class::DBI SYNOPSIS 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; DESCRIPTION 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. AUTHOR Tony Bowden BUGS and QUERIES Please direct all correspondence regarding this module to: bug-Class-DBI-Plugin-RetrieveAll@rt.cpan.org COPYRIGHT and LICENSE Copyright (C) 2004-2006 Kasei. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Class-DBI-Plugin-RetrieveAll-1.04/Changes0000644000175200017520000000033710362702646016623 0ustar tonytonyRevision history for Class::DBI::Plugin::RetrieveAll 1.04 Mon Jan 16 11:08:58 UTC 2006 - Doc tweaks 1.02 Tue Oct 4 11:14:31 UTC 2005 - Added rt.cpan address for bug reports 1.0 Sun Feb 1 2004 - first CPAN version Class-DBI-Plugin-RetrieveAll-1.04/MANIFEST.SKIP0000444000175200017520000000054510320461576017223 0ustar tonytony# Avoid version control files. \bRCS\b \bCVS\b ,v$ ,B$ ,D$ \B\.svn\b aegis.log$ \bconfig$ \bbuild$ # Avoid Makemaker generated and utility files. \bMakefile$ \bblib \bMakeMaker-\d \bpm_to_blib$ \bblibdirs$ # Avoid Module::Build generated and utility files. \bBuild$ \b_build # Avoid temp and backup files. ~$ \.gz$ \.old$ \.bak$ \.swp$ \.tdy$ \#$ \b\.# Class-DBI-Plugin-RetrieveAll-1.04/Makefile.PL0000644000175200017520000000031010007174243017261 0ustar tonytonyuse ExtUtils::MakeMaker; WriteMakefile( 'NAME' => 'Class::DBI::Plugin::RetrieveAll', 'VERSION_FROM' => 'lib/Class/DBI/Plugin/RetrieveAll.pm', 'PREREQ_PM' => { 'Class::DBI' => '0.95', }, ); Class-DBI-Plugin-RetrieveAll-1.04/META.yml0000644000175200017520000000057410362702677016610 0ustar tonytony# http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# name: Class-DBI-Plugin-RetrieveAll version: 1.04 version_from: lib/Class/DBI/Plugin/RetrieveAll.pm installdirs: site requires: Class::DBI: 0.95 distribution_type: module generated_by: ExtUtils::MakeMaker version 6.17 Class-DBI-Plugin-RetrieveAll-1.04/MANIFEST0000644000175200017520000000022410362702667016457 0ustar tonytonyChanges lib/Class/DBI/Plugin/RetrieveAll.pm Makefile.PL MANIFEST This list of files MANIFEST.SKIP META.yml README t/01.t t/pod-coverage.t t/pod.t