ResultSetInstance is now a component on DB, some test cleanup
[dbsrgits/DBIx-Class-Historic.git] / lib / DBIx / Class / DB.pm
1 package DBIx::Class::DB;
2
3 use base qw/DBIx::Class/;
4 use DBIx::Class::Storage::DBI;
5 use DBIx::Class::ClassResolver::PassThrough;
6 use DBI;
7
8 __PACKAGE__->load_components(qw/ResultSetInstance/);
9
10 *dbi_commit = \&txn_commit;
11 *dbi_rollback = \&txn_rollback;
12
13 sub storage { shift->storage_instance(@_); }
14
15 =head1 NAME 
16
17 DBIx::Class::DB - Simple DBIx::Class Database connection by class inheritance
18
19 =head1 SYNOPSIS
20
21   package MyDB;
22
23   use base qw/DBIx::Class/;
24   __PACKAGE__->load_components('DB');
25
26   __PACKAGE__->connection('dbi:...', 'user', 'pass', \%attrs);
27
28   package MyDB::MyTable;
29
30   use base qw/MyDB/;
31   __PACKAGE__->load_components('Core'); # just load this in MyDB if it will always be there
32
33   ...
34
35 =head1 DESCRIPTION
36
37 This class provides a simple way of specifying a database connection.
38
39 =head1 METHODS
40
41 =head2 storage
42
43 Sets or gets the storage backend. Defaults to L<DBIx::Class::Storage::DBI>.
44
45 =head2 class_resolver
46
47 Sets or gets the class to use for resolving a class. Defaults to 
48 L<DBIx::Class::ClassResolver::Passthrough>, which returns whatever you give
49 it. See resolve_class below.
50
51 =cut
52
53 __PACKAGE__->mk_classdata('class_resolver' =>
54                             'DBIx::Class::ClassResolver::PassThrough');
55
56 =head2 connection
57
58   __PACKAGE__->connection($dsn, $user, $pass, $attrs);
59
60 Specifies the arguments that will be passed to DBI->connect(...) to
61 instantiate the class dbh when required.
62
63 =cut
64
65 sub connection {
66   my ($class, @info) = @_;
67   my $storage = DBIx::Class::Storage::DBI->new;
68   $storage->connect_info(\@info);
69   $class->mk_classdata('storage_instance' => $storage);
70 }
71
72 =head2 txn_begin
73
74 Begins a transaction (does nothing if AutoCommit is off).
75
76 =cut
77
78 sub txn_begin { $_[0]->storage->txn_begin }
79
80 =head2 txn_commit
81
82 Commits the current transaction.
83
84 =cut
85
86 sub txn_commit { $_[0]->storage->txn_commit }
87
88 =head2 txn_rollback
89
90 Rolls back the current transaction.
91
92 =cut
93
94 sub txn_rollback { $_[0]->storage->txn_rollback }
95
96 sub resolve_class { return shift->class_resolver->class(@_); }
97
98 1;
99
100 =head1 AUTHORS
101
102 Matt S. Trout <mst@shadowcatsystems.co.uk>
103
104 =head1 LICENSE
105
106 You may distribute this code under the same terms as Perl itself.
107
108 =cut
109