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