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 unless ($INC{"DBIx/Class/CDBICompat.pm"}) {
13 warn "IMPORTANT: DBIx::Class::DB is DEPRECATED AND *WILL* BE REMOVED. DO NOT USE.\n";
16 __PACKAGE__->load_components(qw/ResultSetProxy/);
20 *dbi_commit = \&txn_commit;
21 *dbi_rollback = \&txn_rollback;
24 sub storage { shift->schema_instance(@_)->storage; }
28 DBIx::Class::DB - (DEPRECATED) classdata schema component
32 This class is designed to support the Class::DBI connection-as-classdata style
33 for DBIx::Class. You are *strongly* recommended to use a DBIx::Class::Schema
34 instead; DBIx::Class::DB will not undergo new development and will be moved
35 to being a CDBICompat-only component before 1.0. In order to discourage further
36 use, documentation has been removed as of 0.08000
38 =begin HIDE_BECAUSE_THIS_CLASS_IS_DEPRECATED
44 Sets or gets the storage backend. Defaults to L<DBIx::Class::Storage::DBI>.
50 Sets or gets the class to use for resolving a class. Defaults to
51 L<DBIx::Class::ClassResolver::Passthrough>, which returns whatever you give
52 it. See resolve_class below.
56 __PACKAGE__->mk_classdata('class_resolver' =>
57 'DBIx::Class::ClassResolver::PassThrough');
61 __PACKAGE__->connection($dsn, $user, $pass, $attrs);
63 Specifies the arguments that will be passed to DBI->connect(...) to
64 instantiate the class dbh when required.
69 my ($class, @info) = @_;
70 $class->setup_schema_instance unless $class->can('schema_instance');
71 $class->schema_instance->connection(@info);
74 =head2 setup_schema_instance
76 Creates a class method ->schema_instance which contains a DBIx::Class::Schema;
77 all class-method operations are proxies through to this object. If you don't
78 call ->connection in your DBIx::Class::DB subclass at load time you *must*
79 call ->setup_schema_instance in order for subclasses to find the schema and
80 register themselves with it.
84 sub setup_schema_instance {
87 bless $schema, 'DBIx::Class::Schema';
88 $class->mk_classdata('schema_instance' => $schema);
93 Begins a transaction (does nothing if AutoCommit is off).
97 sub txn_begin { shift->schema_instance->txn_begin(@_); }
101 Commits the current transaction.
105 sub txn_commit { shift->schema_instance->txn_commit(@_); }
109 Rolls back the current transaction.
113 sub txn_rollback { shift->schema_instance->txn_rollback(@_); }
117 Executes a block of code transactionally. If this code reference
118 throws an exception, the transaction is rolled back and the exception
119 is rethrown. See L<DBIx::Class::Schema/"txn_do"> for more details.
123 sub txn_do { shift->schema_instance->txn_do(@_); }
129 warn "resolve_class deprecated as of 0.04999_02" unless $warn++;
130 return shift->class_resolver->class(@_);
134 =head2 resultset_instance
136 Returns an instance of a resultset for this class - effectively
137 mapping the L<Class::DBI> connection-as-classdata paradigm into the
138 native L<DBIx::Class::ResultSet> system.
142 sub resultset_instance {
143 my $class = ref $_[0] || $_[0];
144 my $source = $class->result_source_instance;
145 if ($source->result_class ne $class) {
146 $source = $source->new($source);
147 $source->result_class($class);
149 return $source->resultset;
156 See L<class_resolver>
162 Alias for L<txn_commit>
168 Alias for L<txn_rollback>
170 =end HIDE_BECAUSE_THIS_CLASS_IS_DEPRECATED
174 Matt S. Trout <mst@shadowcatsystems.co.uk>
178 You may distribute this code under the same terms as Perl itself.