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