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