Merge 'trunk' into 'DBIx-Class-current'
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / DB.pm
CommitLineData
ea2e61bf 1package DBIx::Class::DB;
2
bf5ecff9 3use strict;
4use warnings;
5
1edd1722 6use base qw/DBIx::Class/;
7fb16f1a 7use DBIx::Class::Schema;
8b445e33 8use DBIx::Class::Storage::DBI;
11b78bd6 9use DBIx::Class::ClassResolver::PassThrough;
604d9f38 10use DBI;
ea2e61bf 11
c216324a 12unless ($INC{"DBIx/Class/CDBICompat.pm"}) {
13 warn "IMPORTANT: DBIx::Class::DB is DEPRECATED AND *WILL* BE REMOVED. DO NOT USE.\n";
14}
15
80c90f5d 16__PACKAGE__->load_components(qw/ResultSetProxy/);
2d679367 17
bf5ecff9 18{
19 no warnings 'once';
20 *dbi_commit = \&txn_commit;
21 *dbi_rollback = \&txn_rollback;
22}
8091aa91 23
7fb16f1a 24sub storage { shift->schema_instance(@_)->storage; }
2d679367 25
75d07914 26=head1 NAME
34d52be2 27
1c81f831 28DBIx::Class::DB - (DEPRECATED) classdata schema component
34d52be2 29
34d52be2 30=head1 DESCRIPTION
31
66d9ef6b 32This class is designed to support the Class::DBI connection-as-classdata style
33for DBIx::Class. You are *strongly* recommended to use a DBIx::Class::Schema
1c81f831 34instead; DBIx::Class::DB will not undergo new development and will be moved
c216324a 35to being a CDBICompat-only component before 1.0. In order to discourage further
36use, documentation has been removed as of 0.08000
37
38=begin HIDE_BECAUSE_THIS_CLASS_IS_DEPRECATED
34d52be2 39
40=head1 METHODS
41
8091aa91 42=head2 storage
076652e8 43
8091aa91 44Sets or gets the storage backend. Defaults to L<DBIx::Class::Storage::DBI>.
076652e8 45
87c4e602 46=head2 class_resolver
47
48****DEPRECATED****
076652e8 49
75d07914 50Sets or gets the class to use for resolving a class. Defaults to
8091aa91 51L<DBIx::Class::ClassResolver::Passthrough>, which returns whatever you give
52it. See resolve_class below.
076652e8 53
34d52be2 54=cut
55
11b78bd6 56__PACKAGE__->mk_classdata('class_resolver' =>
181a28f4 57 'DBIx::Class::ClassResolver::PassThrough');
8fe001e1 58
8091aa91 59=head2 connection
39fe0e65 60
61 __PACKAGE__->connection($dsn, $user, $pass, $attrs);
62
63Specifies the arguments that will be passed to DBI->connect(...) to
64instantiate the class dbh when required.
65
66=cut
67
8fe001e1 68sub connection {
69 my ($class, @info) = @_;
66d9ef6b 70 $class->setup_schema_instance unless $class->can('schema_instance');
71 $class->schema_instance->connection(@info);
72}
73
74=head2 setup_schema_instance
75
76Creates a class method ->schema_instance which contains a DBIx::Class::Schema;
77all class-method operations are proxies through to this object. If you don't
78call ->connection in your DBIx::Class::DB subclass at load time you *must*
79call ->setup_schema_instance in order for subclasses to find the schema and
80register themselves with it.
81
82=cut
83
84sub setup_schema_instance {
85 my $class = shift;
04786a4c 86 my $schema = {};
87 bless $schema, 'DBIx::Class::Schema';
7fb16f1a 88 $class->mk_classdata('schema_instance' => $schema);
ea2e61bf 89}
90
8091aa91 91=head2 txn_begin
39fe0e65 92
8091aa91 93Begins a transaction (does nothing if AutoCommit is off).
39fe0e65 94
95=cut
96
181a28f4 97sub txn_begin { shift->schema_instance->txn_begin(@_); }
a29644e1 98
8091aa91 99=head2 txn_commit
39fe0e65 100
8091aa91 101Commits the current transaction.
39fe0e65 102
8091aa91 103=cut
104
181a28f4 105sub txn_commit { shift->schema_instance->txn_commit(@_); }
8091aa91 106
107=head2 txn_rollback
108
109Rolls back the current transaction.
39fe0e65 110
111=cut
112
181a28f4 113sub txn_rollback { shift->schema_instance->txn_rollback(@_); }
114
115=head2 txn_do
116
117Executes a block of code transactionally. If this code reference
118throws an exception, the transaction is rolled back and the exception
bc0c9800 119is rethrown. See L<DBIx::Class::Schema/"txn_do"> for more details.
181a28f4 120
121=cut
122
123sub txn_do { shift->schema_instance->txn_do(@_); }
8b445e33 124
8452e496 125{
126 my $warn;
127
128 sub resolve_class {
129 warn "resolve_class deprecated as of 0.04999_02" unless $warn++;
130 return shift->class_resolver->class(@_);
131 }
7fb16f1a 132}
11b78bd6 133
7eb4ecc8 134=head2 resultset_instance
135
136Returns an instance of a resultset for this class - effectively
137mapping the L<Class::DBI> connection-as-classdata paradigm into the
138native L<DBIx::Class::ResultSet> system.
139
140=cut
141
142sub resultset_instance {
143 my $class = ref $_[0] || $_[0];
144 my $source = $class->result_source_instance;
145 if ($source->result_class ne $class) {
146 $source = $source->new($source);
147 $source->result_class($class);
148 }
149 return $source->resultset;
150}
151
152=head2 resolve_class
153
154****DEPRECATED****
155
156See L<class_resolver>
157
158=head2 dbi_commit
159
160****DEPRECATED****
161
162Alias for L<txn_commit>
163
164=head2 dbi_rollback
165
166****DEPRECATED****
167
168Alias for L<txn_rollback>
169
c216324a 170=end HIDE_BECAUSE_THIS_CLASS_IS_DEPRECATED
171
34d52be2 172=head1 AUTHORS
173
daec44b8 174Matt S. Trout <mst@shadowcatsystems.co.uk>
34d52be2 175
176=head1 LICENSE
177
178You may distribute this code under the same terms as Perl itself.
179
180=cut
181
76b2b77c 1821;