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 {
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 always be there
48 This class is designed to support the Class::DBI connection-as-classdata style
49 for DBIx::Class. You are *strongly* recommended to use a DBIx::Class::Schema
50 instead; DBIx::Class::DB will continue to be supported but new development
51 will be focused on Schema-based DBIx::Class setups.
57 Sets or gets the storage backend. Defaults to L<DBIx::Class::Storage::DBI>.
59 =head2 class_resolver ****DEPRECATED****
61 Sets or gets the class to use for resolving a class. Defaults to
62 L<DBIx::Class::ClassResolver::Passthrough>, which returns whatever you give
63 it. See resolve_class below.
67 __PACKAGE__->mk_classdata('class_resolver' =>
68 'DBIx::Class::ClassResolver::PassThrough');
72 __PACKAGE__->connection($dsn, $user, $pass, $attrs);
74 Specifies the arguments that will be passed to DBI->connect(...) to
75 instantiate the class dbh when required.
80 my ($class, @info) = @_;
81 $class->setup_schema_instance unless $class->can('schema_instance');
82 $class->schema_instance->connection(@info);
85 =head2 setup_schema_instance
87 Creates a class method ->schema_instance which contains a DBIx::Class::Schema;
88 all class-method operations are proxies through to this object. If you don't
89 call ->connection in your DBIx::Class::DB subclass at load time you *must*
90 call ->setup_schema_instance in order for subclasses to find the schema and
91 register themselves with it.
95 sub setup_schema_instance {
97 my $schema = bless({}, 'DBIx::Class::Schema');
98 $class->mk_classdata('schema_instance' => $schema);
103 Begins a transaction (does nothing if AutoCommit is off).
107 sub txn_begin { $_[0]->schema_instance->txn_begin }
111 Commits the current transaction.
115 sub txn_commit { $_[0]->schema_instance->txn_commit }
119 Rolls back the current transaction.
123 sub txn_rollback { $_[0]->schema_instance->txn_rollback }
129 warn "resolve_class deprecated as of 0.04999_02" unless $warn++;
130 return shift->class_resolver->class(@_);
138 Matt S. Trout <mst@shadowcatsystems.co.uk>
142 You may distribute this code under the same terms as Perl itself.