]> jfr.im git - irc/SurrealServices/srsv.git/blob - branches/mus-0.4.x-devel/SrSv/DB/StubGen.pm
The SrSv/DB directory was removed because of a conflict. This is to
[irc/SurrealServices/srsv.git] / branches / mus-0.4.x-devel / SrSv / DB / StubGen.pm
1 # This file is part of Invid
2 #
3 # Invid is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License version 2.1 as published by the Free Software Foundation.
6
7 # This library is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 # Lesser General Public License for more details.
11
12 # You should have received a copy of the GNU Lesser General Public
13 # License along with this library; if not, write to the Free Software
14 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15
16 # Copyright Adam Schrotenboer <adam@tabris.net> 2007, 2008
17 #
18
19 # This code is based in large part on the MySQL::Stub from SrSv, as well as
20 # the DB::Sub from M2000's CMS.
21
22 =head1 NAME
23
24 Invid::DB::Stub - Create functions for SQL queries
25
26 =cut
27
28 package SrSv::DB::StubGen;
29
30 use strict;
31 use warnings;
32
33 require SrSv::DB::StubGen::Stub;
34
35 sub import {
36 my $package = caller;
37
38 shift @_; # Remove package name from arg list.
39 my %stubhash = @_; # Basically we coerce the list back into a hash.
40 my $generator = $stubhash{generator};
41 my $dbh = $stubhash{dbh};
42 my $sub = sub {
43 import SrSv::DB::StubGen::Stub ($package, $dbh, @_);
44 };
45
46 # Export subroutine into caller's namespace.
47 {
48 no strict 'refs';
49 *{"${package}::${generator}"} = $sub;
50 }
51 }
52
53 __END__
54
55 =head1 SYNOPSIS
56
57 use SrSv::DB::StubGen {
58 dbh => $dbh
59 generator => 'main_sql_stub',
60 };
61
62 =head1 PURPOSE
63
64 The point of this is that although SrSv::DB::Stub is bloody useful, it
65 only lets you use one $dbh per program. What if you have more than one
66 database?
67
68 =head1 DESCRIPTION
69
70 See SrSv::DB::Stub for how you use the generator function.
71
72 However, instead of
73
74 use SrSv::DB::Stub ( ... )
75
76 one uses instead
77
78 main_sql_stub ( ... )
79
80 =cut