1 package DBIx::Class::DB;
6 use base qw/DBIx::Class/;
7 use DBIx::Class::Schema;
8 use DBIx::Class::Storage::DBI;
9 use DBIx::Class::ClassResolver::PassThrough;
12 __PACKAGE__->load_components(qw/ResultSetProxy/);
16 *dbi_commit = \&txn_commit;
17 *dbi_rollback = \&txn_rollback;
20 sub storage { shift->schema_instance(@_)->storage; }
24 DBIx::Class::DB - (DEPRECATED) classdata schema component
30 use base qw/DBIx::Class/;
31 __PACKAGE__->load_components('DB');
33 __PACKAGE__->connection('dbi:...', 'user', 'pass', \%attrs);
35 package MyDB::MyTable;
38 __PACKAGE__->load_components('Core'); # just load this in MyDB if it will
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
47 instead; DBIx::Class::DB will not undergo new development and will be moved
48 to being a CDBICompat-only component before 1.0.
54 Sets or gets the storage backend. Defaults to L<DBIx::Class::Storage::DBI>.
60 Sets or gets the class to use for resolving a class. Defaults to
61 L<DBIx::Class::ClassResolver::Passthrough>, which returns whatever you give
62 it. See resolve_class below.
66 __PACKAGE__->mk_classdata('class_resolver' =>
67 'DBIx::Class::ClassResolver::PassThrough');
71 __PACKAGE__->connection($dsn, $user, $pass, $attrs);
73 Specifies the arguments that will be passed to DBI->connect(...) to
74 instantiate the class dbh when required.
79 my ($class, @info) = @_;
80 $class->setup_schema_instance unless $class->can('schema_instance');
81 $class->schema_instance->connection(@info);
84 =head2 setup_schema_instance
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.
94 sub setup_schema_instance {
97 bless $schema, 'DBIx::Class::Schema';
98 $class->mk_classdata('schema_instance' => $schema);
103 Begins a transaction (does nothing if AutoCommit is off).
107 sub txn_begin { shift->schema_instance->txn_begin(@_); }
111 Commits the current transaction.
115 sub txn_commit { shift->schema_instance->txn_commit(@_); }
119 Rolls back the current transaction.
123 sub txn_rollback { shift->schema_instance->txn_rollback(@_); }
127 Executes a block of code transactionally. If this code reference
128 throws an exception, the transaction is rolled back and the exception
129 is rethrown. See L<DBIx::Class::Schema/"txn_do"> for more details.
133 sub txn_do { shift->schema_instance->txn_do(@_); }
139 warn "resolve_class deprecated as of 0.04999_02" unless $warn++;
140 return shift->class_resolver->class(@_);
144 =head2 resultset_instance
146 Returns an instance of a resultset for this class - effectively
147 mapping the L<Class::DBI> connection-as-classdata paradigm into the
148 native L<DBIx::Class::ResultSet> system.
152 sub resultset_instance {
153 my $class = ref $_[0] || $_[0];
154 my $source = $class->result_source_instance;
155 if ($source->result_class ne $class) {
156 $source = $source->new($source);
157 $source->result_class($class);
159 return $source->resultset;
166 See L<class_resolver>
172 Alias for L<txn_commit>
178 Alias for L<txn_rollback>
182 Matt S. Trout <mst@shadowcatsystems.co.uk>
186 You may distribute this code under the same terms as Perl itself.