item => head2 in docs
[dbsrgits/DBIx-Class.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 =head2 storage
35
36 Sets or gets the storage backend. Defaults to L<DBIx::Class::Storage::DBI>.
37
38 =head2 class_resolver
39
40 Sets or gets the class to use for resolving a class. Defaults to 
41 L<DBIx::Class::ClassResolver::Passthrough>, which returns whatever you give
42 it. See resolve_class below.
43
44 =cut
45
46 __PACKAGE__->mk_classdata('storage');
47 __PACKAGE__->mk_classdata('class_resolver' =>
48                             'DBIx::Class::ClassResolver::PassThrough');
49
50 =head2 connection
51
52   __PACKAGE__->connection($dsn, $user, $pass, $attrs);
53
54 Specifies the arguments that will be passed to DBI->connect(...) to
55 instantiate the class dbh when required.
56
57 =cut
58
59 sub connection {
60   my ($class, @info) = @_;
61   my $storage = DBIx::Class::Storage::DBI->new;
62   $storage->connect_info(\@info);
63   $class->storage($storage);
64 }
65
66 =head2 dbi_commit
67
68 Issues a commit against the current dbh.
69
70 =cut
71
72 sub dbi_commit { $_[0]->storage->commit; }
73
74 =head2 dbi_rollback
75
76 Issues a rollback against the current dbh.
77
78 =cut
79
80 sub dbi_rollback { $_[0]->storage->rollback; }
81
82 sub resolve_class { return shift->class_resolver->class(@_); }
83
84 1;
85
86 =head1 AUTHORS
87
88 Matt S. Trout <mst@shadowcatsystems.co.uk>
89
90 =head1 LICENSE
91
92 You may distribute this code under the same terms as Perl itself.
93
94 =cut
95