Class-DBI-AbstractSearch-0.07/0000755000175000017500000000000010321107331017377 5ustar miyagawamiyagawa00000000000000Class-DBI-AbstractSearch-0.07/t/0000755000175000017500000000000010321107331017642 5ustar miyagawamiyagawa00000000000000Class-DBI-AbstractSearch-0.07/t/00_compile.t0000644000175000017500000000012210303520425021754 0ustar miyagawamiyagawa00000000000000use strict; use Test::More tests => 1; require_ok 'Class::DBI::AbstractSearch'; Class-DBI-AbstractSearch-0.07/t/01_abstract.t0000644000175000017500000000202410321107161022131 0ustar miyagawamiyagawa00000000000000use strict; use Test::More; BEGIN { eval "use DBD::SQLite"; plan $@ ? (skip_all => 'needs DND::SQLite for testing') : (tests => 2); } use DBI; my $DB = "t/testdb"; unlink $DB if -e $DB; my @DSN = ("dbi:SQLite:dbname=$DB", '', '', { AutoCommit => 1 }); DBI->connect(@DSN)->do(<set_db(Main => @DSN); __PACKAGE__->table('film'); __PACKAGE__->columns(Primary => qw(id)); __PACKAGE__->columns(All => qw(title)); use Class::DBI::AbstractSearch; package main; for my $i (1..50) { Film->create({ title => "title $i", }); } { my @films = Film->search_where(title => [ "title 10", "title 20" ]); is @films, 2, "films return 2"; @films = Film->search_where( { title => { 'like' => 'title%' } }, { limit_dialect => 'LimitOffset', limit => 5, offset => 10 } ); is @films, 5, "films return 5"; } END { unlink $DB if -e $DB } Class-DBI-AbstractSearch-0.07/MANIFEST0000644000175000017500000000030110321107331020522 0ustar miyagawamiyagawa00000000000000Changes MANIFEST This list of files Makefile.PL lib/Class/DBI/AbstractSearch.pm t/00_compile.t t/01_abstract.t META.yml Module meta-data (added by MakeMaker) Class-DBI-AbstractSearch-0.07/lib/0000755000175000017500000000000010321107331020145 5ustar miyagawamiyagawa00000000000000Class-DBI-AbstractSearch-0.07/lib/Class/0000755000175000017500000000000010321107331021212 5ustar miyagawamiyagawa00000000000000Class-DBI-AbstractSearch-0.07/lib/Class/DBI/0000755000175000017500000000000010321107331021610 5ustar miyagawamiyagawa00000000000000Class-DBI-AbstractSearch-0.07/lib/Class/DBI/AbstractSearch.pm0000644000175000017500000000626310321107315025050 0ustar miyagawamiyagawa00000000000000package Class::DBI::AbstractSearch; use strict; use vars qw($VERSION @EXPORT); $VERSION = 0.07; require Exporter; *import = \&Exporter::import; @EXPORT = qw(search_where); use SQL::Abstract::Limit; sub search_where { my $class = shift; my $where = (ref $_[0]) ? $_[0] : { @_ }; my $attr = (ref $_[0]) ? $_[1] : undef; my $order = ($attr) ? delete($attr->{order_by}) : undef; my $limit = ($attr) ? delete($attr->{limit}) : undef; my $offset = ($attr) ? delete($attr->{offset}) : undef; # order is deprecated, but still backward compatible if ($attr && exists($attr->{order})) { $order = delete($attr->{order}); } $class->can('retrieve_from_sql') or do { require Carp; Carp::croak("$class should inherit from Class::DBI >= 0.90"); }; my $sql = SQL::Abstract::Limit->new(%$attr); my($phrase, @bind) = $sql->where($where, $order, $limit, $offset); $phrase =~ s/^\s*WHERE\s*//i; return $class->retrieve_from_sql($phrase, @bind); } 1; __END__ =head1 NAME Class::DBI::AbstractSearch - Abstract Class::DBI's SQL with SQL::Abstract::Limit =head1 SYNOPSIS package CD::Music; use Class::DBI::AbstractSearch; package main; my @music = CD::Music->search_where( artist => [ 'Ozzy', 'Kelly' ], status => { '!=', 'outdated' }, ); my @misc = CD::Music->search_where( { artist => [ 'Ozzy', 'Kelly' ], status => { '!=', 'outdated' } }, { order_by => "reldate DESC", limit_dialect => 'LimitOffset', limit => 1 offset => 2 }); =head1 DESCRIPTION Class::DBI::AbstractSearch is a Class::DBI plugin to glue SQL::Abstract::Limit into Class::DBI. =head1 METHODS Using this module adds following methods into your data class. =over 4 =item search_where $class->search_where(%where); Takes a hash to specify WHERE clause. See L for hash options. $class->search_where(\%where,\%attrs); Takes hash reference to specify WHERE clause. See L for hash options. Takes a hash reference to specify additional query attributes. Class::DBI::AbstractSearch uses these attributes: =over 4 =item * B Array reference of fields that will be used to order the results of your query. =item * B Scalar, DBI handle, object class, etc. that describes the syntax model for a LIMIT/OFFSET SQL clause. Please see SQL::Abstract::Limit for more information. =item * B Scalar value that will be used for LIMIT argument in a query. =item * B Scalar value that will be used for OFFSET argument in a query. =back Any other attributes are passed to the SQL::Abstract::Limit constructor, and can be used to control how queries are created. For example, to use 'AND' instead of 'OR' by default, use: $class->search_where(\%where, { logic => 'AND' }); =head1 AUTHOR Tatsuhiko Miyagawa Emiyagawa@bulknews.netE with some help from cdbi-talk mailing list, especially: Tim Bunce Simon Wilcox Tony Bowden This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO L, L, L =cut Class-DBI-AbstractSearch-0.07/Changes0000644000175000017500000000162610321107264020704 0ustar miyagawamiyagawa00000000000000Revision history for Perl extension Class::DBI::AbstractSearch 0.07 Thu Oct 6 02:40:16 UTC 2005 - Fixed test suite for Windows which can't rm files while opening [cpan #14935] 0.06 Tue Aug 23 22:03:22 UTC 2005 - Now uses SQL::Abstract::Limit to allow limit SQL (Thanks to David R. Baird) 0.05 Wed Apr 7 18:30:27 JST 2004 - renamed 'order' to 'order_by', used in Class::DBI's search (Thanks to Hajime Sugawara) 0.04 Thu Feb 19 19:00:53 JST 2004 - Fixed some typos. (Thanks to Jay Strauss) * Added support for SQL::Abstract->new() option (Thanks to darren chamberlain) 0.03 Wed Jul 30 20:49:28 JST 2003 - Fixed warnings for repeated 'my $where' 0.02 Mon Jun 30 10:37:15 2003 - modified input parameters for 'search_where' to accept an optional %attrs hash ref. (Thanks to Aaron Straup Cope) 0.01 Tue Feb 4 23:33:46 2003 - original version Class-DBI-AbstractSearch-0.07/Makefile.PL0000644000175000017500000000041210303520425021351 0ustar miyagawamiyagawa00000000000000use ExtUtils::MakeMaker; WriteMakefile( 'NAME' => 'Class::DBI::AbstractSearch', 'VERSION_FROM' => 'lib/Class/DBI/AbstractSearch.pm', # finds $VERSION 'PREREQ_PM' => { Test::More => 0.32, Class::DBI => 0.90, SQL::Abstract::Limit => 0.1, }, ); Class-DBI-AbstractSearch-0.07/META.yml0000644000175000017500000000070210321107331020647 0ustar miyagawamiyagawa00000000000000# http://module-build.sourceforge.net/META-spec.html #XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# name: Class-DBI-AbstractSearch version: 0.07 version_from: lib/Class/DBI/AbstractSearch.pm installdirs: site requires: Class::DBI: 0.9 SQL::Abstract::Limit: 0.1 Test::More: 0.32 distribution_type: module generated_by: ExtUtils::MakeMaker version 6.27