Merge 'trunk' into 'DBIx-Class-C3'
[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 =head1 NAME 
9
10 DBIx::Class::DB - Simple DBIx::Class Database connection by class inheritance
11
12 =head1 SYNOPSIS
13
14   package MyDB;
15
16   use base qw/DBIx::Class/;
17   __PACKAGE__->load_components('DB');
18
19   __PACKAGE__->connection('dbi:...', 'user', 'pass', \%attrs);
20
21   package MyDB::MyTable;
22
23   use base qw/MyDB/;
24   __PACKAGE__->load_components('Core');
25
26   ...
27
28 =head1 DESCRIPTION
29
30 This class provides a simple way of specifying a database connection.
31
32 =head1 METHODS
33
34 =over 4
35
36
37 =item storage
38
39 Which storage backend to be used. Defaults to L<DBIx::Class::Storage::DBI>
40
41 =item class_resolver
42
43 Which class to use for resolving a class. Defaults to 
44 L<DBIx::Class::ClassResolver::Passthrough>, which returns whatever you throw
45 at it. See resolve_class below.
46
47 =cut
48
49 __PACKAGE__->mk_classdata('storage');
50 __PACKAGE__->mk_classdata('class_resolver' =>
51                             'DBIx::Class::ClassResolver::PassThrough');
52
53 =item connection
54
55   __PACKAGE__->connection($dsn, $user, $pass, $attrs);
56
57 Specifies the arguments that will be passed to DBI->connect(...) to
58 instantiate the class dbh when required.
59
60 =cut
61
62 sub connection {
63   my ($class, @info) = @_;
64   my $storage = DBIx::Class::Storage::DBI->new;
65   $storage->connect_info(\@info);
66   $class->storage($storage);
67 }
68
69 =item dbi_commit
70
71   $class->dbi_commit;
72
73 Issues a commit again the current dbh
74
75 =cut
76
77 sub dbi_commit { $_[0]->storage->commit; }
78
79 =item dbi_rollback
80
81   $class->dbi_rollback;
82
83 Issues a rollback again the current dbh
84
85 =cut
86
87 sub dbi_rollback { $_[0]->storage->rollback; }
88
89 sub resolve_class { return shift->class_resolver->class(@_); }
90
91 1;
92
93 =back
94
95 =head1 AUTHORS
96
97 Matt S. Trout <mst@shadowcatsystems.co.uk>
98
99 =head1 LICENSE
100
101 You may distribute this code under the same terms as Perl itself.
102
103 =cut
104