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