Fixed DBICTest Schema class names, added class_resolver system to make them work
[dbsrgits/DBIx-Class-Historic.git] / lib / DBIx / Class / DB.pm
CommitLineData
ea2e61bf 1package DBIx::Class::DB;
2
3use base qw/Class::Data::Inheritable/;
8b445e33 4use DBIx::Class::Storage::DBI;
11b78bd6 5use DBIx::Class::ClassResolver::PassThrough;
604d9f38 6use DBI;
ea2e61bf 7
34d52be2 8=head1 NAME
9
8b445e33 10DBIx::Class::DB - Simple DBIx::Class Database connection by class inheritance
34d52be2 11
12=head1 SYNOPSIS
13
8b445e33 14 package MyDB;
15
16 use base qw/DBIx::Class/;
4a9d7cae 17 __PACKAGE__->load_components('Core');
8b445e33 18
19 __PACKAGE__->connection('dbi:...', 'user', 'pass', \%attrs);
20
21 package MyDB::MyTable;
22
23 use base qw/MyDB/;
4a9d7cae 24
25 ...
8b445e33 26
34d52be2 27=head1 DESCRIPTION
28
8b445e33 29This class provides a simple way of specifying a database connection.
34d52be2 30
31=head1 METHODS
32
33=over 4
34
35=cut
36
8b445e33 37__PACKAGE__->mk_classdata('storage');
11b78bd6 38__PACKAGE__->mk_classdata('class_resolver' =>
39 'DBIx::Class::ClassResolver::PassThrough');
8fe001e1 40
39fe0e65 41=item connection
42
43 __PACKAGE__->connection($dsn, $user, $pass, $attrs);
44
45Specifies the arguments that will be passed to DBI->connect(...) to
46instantiate the class dbh when required.
47
48=cut
49
8fe001e1 50sub connection {
51 my ($class, @info) = @_;
8b445e33 52 my $storage = DBIx::Class::Storage::DBI->new;
53 $storage->connect_info(\@info);
54 $class->storage($storage);
ea2e61bf 55}
56
39fe0e65 57=item dbi_commit
58
59 $class->dbi_commit;
60
61Issues a commit again the current dbh
62
63=cut
64
8b445e33 65sub dbi_commit { $_[0]->storage->commit; }
a29644e1 66
39fe0e65 67=item dbi_rollback
68
69 $class->dbi_rollback;
70
71Issues a rollback again the current dbh
72
73=cut
74
8b445e33 75sub dbi_rollback { $_[0]->storage->rollback; }
76
11b78bd6 77sub resolve_class { return shift->class_resolver->class(@_); }
78
ea2e61bf 791;
34d52be2 80
81=back
82
83=head1 AUTHORS
84
85Matt S. Trout <perl-stuff@trout.me.uk>
86
87=head1 LICENSE
88
89You may distribute this code under the same terms as Perl itself.
90
91=cut
92