1 package DBIx::Class::DB;
3 use base qw/DBIx::Class/;
4 use DBIx::Class::Schema;
5 use DBIx::Class::Storage::DBI;
6 use DBIx::Class::ClassResolver::PassThrough;
9 __PACKAGE__->load_components(qw/ResultSetProxy/);
11 *dbi_commit = \&txn_commit;
12 *dbi_rollback = \&txn_rollback;
14 sub storage { shift->schema_instance(@_)->storage; }
16 sub resultset_instance {
17 my $class = ref $_[0] || $_[0];
18 my $source = $class->result_source_instance;
19 if ($source->result_class ne $class) {
20 $source = $source->new($source);
21 $source->result_class($class);
23 return $source->resultset;
28 DBIx::Class::DB - Non-recommended classdata schema component
34 use base qw/DBIx::Class/;
35 __PACKAGE__->load_components('DB');
37 __PACKAGE__->connection('dbi:...', 'user', 'pass', \%attrs);
39 package MyDB::MyTable;
42 __PACKAGE__->load_components('Core'); # just load this in MyDB if it will
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.
58 Sets or gets the storage backend. Defaults to L<DBIx::Class::Storage::DBI>.
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.
70 __PACKAGE__->mk_classdata('class_resolver' =>
71 'DBIx::Class::ClassResolver::PassThrough');
75 __PACKAGE__->connection($dsn, $user, $pass, $attrs);
77 Specifies the arguments that will be passed to DBI->connect(...) to
78 instantiate the class dbh when required.
83 my ($class, @info) = @_;
84 $class->setup_schema_instance unless $class->can('schema_instance');
85 $class->schema_instance->connection(@info);
88 =head2 setup_schema_instance
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.
98 sub setup_schema_instance {
100 my $schema = bless({}, 'DBIx::Class::Schema');
101 $class->mk_classdata('schema_instance' => $schema);
106 Begins a transaction (does nothing if AutoCommit is off).
110 sub txn_begin { shift->schema_instance->txn_begin(@_); }
114 Commits the current transaction.
118 sub txn_commit { shift->schema_instance->txn_commit(@_); }
122 Rolls back the current transaction.
126 sub txn_rollback { shift->schema_instance->txn_rollback(@_); }
130 Executes a block of code transactionally. If this code reference
131 throws an exception, the transaction is rolled back and the exception
132 is rethrown. See L<DBIx::Class::Schema/"txn_do"> for more details.
136 sub txn_do { shift->schema_instance->txn_do(@_); }
142 warn "resolve_class deprecated as of 0.04999_02" unless $warn++;
143 return shift->class_resolver->class(@_);
151 Matt S. Trout <mst@shadowcatsystems.co.uk>
155 You may distribute this code under the same terms as Perl itself.