root/Class-DBI-AbstractSearch/trunk/lib/Class/DBI/AbstractSearch.pm

Revision 833 (checked in by miyagawa, 18 years ago)

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 package Class::DBI::AbstractSearch;
2
3 use strict;
4 use vars qw($VERSION @EXPORT);
5 $VERSION = 0.01;
6
7 require Exporter;
8 *import = \&Exporter::import;
9 @EXPORT = qw(search_where);
10
11 use SQL::Abstract;
12
13 sub search_where {
14     my($class, %where) = @_;
15     $class->can('retrieve_from_sql') or do {
16         require Carp;
17         Carp::croak("$class should inherit from Class::DBI >= 0.90");
18     };
19     my $sql = SQL::Abstract->new; # XXX how do we supply options here?
20     my($where, @bind) = $sql->where(\%where);
21     $where =~ s/^\s*WHERE\s*//i;
22     return $class->retrieve_from_sql($where, @bind);
23 }
24
25 1;
26 __END__
27
28 =head1 NAME
29
30 Class::DBI::AbstractSearch - Abstract Class::DBI's SQL with SQL::Abstract
31
32 =head1 SYNOPSIS
33
34   package CD::Music;
35   use Class::DBI::AbstractSearch;
36
37   pacage main;
38   my @music = CD::Music->search_where(
39       artist => [ 'Ozzy', 'Kelly' ],
40       status => { '!=', 'outdated' },
41   );
42
43 =head1 DESCRIPTION
44
45 Class::DBI::AbstractSearch is a Class::DBI plugin to glue
46 SQL::Abstract into Class::DBI.
47
48 =head1 METHODS
49
50 Using this module adds following methods into your data class.
51
52 =over 4
53
54 =item search_where
55
56   $class->search_where(%where);
57
58 takes hash to specify WHERE clause. See L<SQL::Abstract> for hash
59 options.
60
61 =head1 AUTHOR
62
63 Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt> with some help from
64 cdbi-talk maling list, especially:
65
66   Tim Bunce
67   Simon Wilcox
68   Tony Bowden
69
70 This library is free software; you can redistribute it and/or modify
71 it under the same terms as Perl itself.
72
73 =head1 SEE ALSO
74
75 L<Class::DBI>, L<SQL::Abstract>
76
77 =cut
Note: See TracBrowser for help on using the browser.